@2112-lab/central-plant 0.1.71 → 0.1.73

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.
@@ -19434,7 +19434,8 @@ var ComponentDataManager = /*#__PURE__*/function (_BaseDisposable) {
19434
19434
  tags: component.tags || [],
19435
19435
  // Preserve S3 metadata
19436
19436
  isS3Component: component.isS3Component,
19437
- s3Path: component.s3Path
19437
+ s3Path: component.s3Path,
19438
+ preLoad: component.preLoad
19438
19439
  };
19439
19440
  return _objectSpread2(_objectSpread2({}, baseData), {}, {
19440
19441
  metadata: component.metadata || {},
@@ -27929,7 +27930,7 @@ var ModelManager = /*#__PURE__*/function () {
27929
27930
  key: "preloadMissingModels",
27930
27931
  value: (function () {
27931
27932
  var _preloadMissingModels = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(data, componentDictionary) {
27932
- var _data$scene, _data$scene2, requiredModels, preloaderStatus, cachedModels, missingModels, _iterator, _step, modelKey, _t5, _t6;
27933
+ var _data$scene, _data$scene2, requiredModels, preloaderStatus, cachedModels, missingModels, basePath, modelUrls, _iterator, _step, modelKey, _t5, _t6;
27933
27934
  return _regenerator().w(function (_context4) {
27934
27935
  while (1) switch (_context4.n) {
27935
27936
  case 0:
@@ -27946,25 +27947,58 @@ var ModelManager = /*#__PURE__*/function () {
27946
27947
  return _context4.a(2);
27947
27948
  case 1:
27948
27949
  requiredModels = new Set();
27950
+ console.log("\uD83D\uDD0D Checking ".concat(data.scene.children.length, " scene objects for required models..."));
27949
27951
  data.scene.children.forEach(function (child) {
27950
- var _child$userData, _child$userData2;
27951
- if ((_child$userData = child.userData) !== null && _child$userData !== void 0 && _child$userData.libraryId && componentDictionary[(_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.libraryId]) {
27952
- var _child$userData3;
27953
- var modelKey = componentDictionary[(_child$userData3 = child.userData) === null || _child$userData3 === void 0 ? void 0 : _child$userData3.libraryId].modelKey;
27954
- if (modelKey) {
27955
- requiredModels.add(modelKey);
27952
+ var _child$userData;
27953
+ var libraryId = (_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.libraryId;
27954
+ if (libraryId) {
27955
+ if (componentDictionary[libraryId]) {
27956
+ var modelKey = componentDictionary[libraryId].modelKey;
27957
+ if (modelKey) {
27958
+ requiredModels.add(modelKey);
27959
+ // console.log(` Found required model for ${libraryId}: ${modelKey}`)
27960
+ } else {
27961
+ console.warn(" Item ".concat(libraryId, " has no modelKey in dictionary"));
27962
+ }
27963
+ } else {
27964
+ console.warn(" Item ".concat(libraryId, " found in scene but missing from dictionary"));
27956
27965
  }
27957
27966
  }
27958
27967
  });
27959
- console.log('🔍 Required models for this scene:', Array.from(requiredModels));
27968
+ console.log('🔍 Required models for this scene (Set):', Array.from(requiredModels));
27960
27969
  _context4.n = 2;
27961
27970
  return this.verifyModelPreloaderCache();
27962
27971
  case 2:
27963
27972
  preloaderStatus = _context4.v;
27964
27973
  cachedModels = preloaderStatus.cachedModels;
27974
+ console.log('ModelPreloader cached models:', cachedModels);
27975
+
27976
+ // Calculate missing models for IN-MEMORY preloading
27965
27977
  missingModels = Array.from(requiredModels).filter(function (model) {
27966
27978
  return !cachedModels.includes(model);
27967
27979
  });
27980
+ console.log('Missing models (calculated):', missingModels);
27981
+
27982
+ // OPTIONAL: Prime persistent browser cache (Cache Storage) using injected primer
27983
+ // We prime ALL required models to ensure they are in the persistent cache, even if already in memory
27984
+ if (requiredModels.size > 0 && this.sceneViewer && this.sceneViewer.centralPlant) {
27985
+ // Construct URLs based on preloader's base path
27986
+ basePath = modelPreloader.modelsBasePath || '/library/models/';
27987
+ modelUrls = Array.from(requiredModels).map(function (key) {
27988
+ return "".concat(basePath).concat(key);
27989
+ });
27990
+ console.log("\uD83D\uDCBE Priming persistent cache for ".concat(modelUrls.length, " assets..."));
27991
+ this.sceneViewer.centralPlant.primeCache(modelUrls).then(function (result) {
27992
+ if (result && !result.skipped) {
27993
+ console.log("\u2705 Persistent cache primed: ".concat(result.success, " success, ").concat(result.failed, " failed"));
27994
+ if (result.failed > 0) {
27995
+ console.warn('Cache priming failures:', result.errors);
27996
+ }
27997
+ }
27998
+ }).catch(function (err) {
27999
+ return console.warn('Persistent cache priming failed:', err);
28000
+ });
28001
+ }
27968
28002
  if (!(missingModels.length > 0)) {
27969
28003
  _context4.n = 12;
27970
28004
  break;
@@ -27972,7 +28006,7 @@ var ModelManager = /*#__PURE__*/function () {
27972
28006
  console.warn('⚠️ Some required models are not cached:', missingModels);
27973
28007
  console.log('🔄 Attempting to preload missing models...');
27974
28008
 
27975
- // Preload missing models
28009
+ // Preload missing models (Main in-memory preloader)
27976
28010
  _iterator = _createForOfIteratorHelper(missingModels);
27977
28011
  _context4.p = 3;
27978
28012
  _iterator.s();
@@ -28107,19 +28141,22 @@ var ModelManager = /*#__PURE__*/function () {
28107
28141
  key: "loadComponentDictionary",
28108
28142
  value: (function () {
28109
28143
  var _loadComponentDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
28110
- var response, _t7;
28144
+ var response, dict, _t7;
28111
28145
  return _regenerator().w(function (_context6) {
28112
28146
  while (1) switch (_context6.n) {
28113
28147
  case 0:
28114
28148
  _context6.p = 0;
28149
+ console.log('🔄 ModelManager loading component dictionary...');
28115
28150
  _context6.n = 1;
28116
- return fetch('./library/component-dictionary.json');
28151
+ return fetch('/library/component-dictionary.json');
28117
28152
  case 1:
28118
28153
  response = _context6.v;
28119
28154
  _context6.n = 2;
28120
28155
  return response.json();
28121
28156
  case 2:
28122
- return _context6.a(2, _context6.v);
28157
+ dict = _context6.v;
28158
+ console.log('✅ ModelManager loaded dictionary:', Object.keys(dict).length, 'entries');
28159
+ return _context6.a(2, dict);
28123
28160
  case 3:
28124
28161
  _context6.p = 3;
28125
28162
  _t7 = _context6.v;
@@ -29854,9 +29891,9 @@ var SceneOperationsManager = /*#__PURE__*/function () {
29854
29891
  // Store current scene data even for default scene
29855
29892
  component.currentSceneData = data;
29856
29893
 
29857
- // Use the consolidated scene loading function
29894
+ // Use the consolidated scene loading function (treat as imported to ensure consistent behavior)
29858
29895
  _context8.n = 4;
29859
- return this.loadSceneData(data, false);
29896
+ return this.loadSceneFromData(data);
29860
29897
  case 4:
29861
29898
  _context8.n = 6;
29862
29899
  break;
@@ -34657,7 +34694,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34657
34694
  * Initialize the CentralPlant manager
34658
34695
  *
34659
34696
  * @constructor
34660
- * @version 0.1.71
34697
+ * @version 0.1.73
34661
34698
  * @updated 2025-10-22
34662
34699
  *
34663
34700
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -34696,6 +34733,9 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34696
34733
  // Initialize internals handler
34697
34734
  _this.internals = new CentralPlantInternals(_this);
34698
34735
 
34736
+ // Optional cache primer function (dependency injection)
34737
+ _this.cachePrimer = null;
34738
+
34699
34739
  // Initialize utilities immediately (they don't need scene viewer)
34700
34740
  _this.internals.initializeUtilities();
34701
34741
 
@@ -34723,6 +34763,54 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34723
34763
  return this.internals.setSceneViewer(sceneViewer);
34724
34764
  }
34725
34765
 
34766
+ /**
34767
+ * Set the cache primer function (dependency injection)
34768
+ * @param {Function} primerFn - Function that takes array of URLs and primes the cache
34769
+ */
34770
+ }, {
34771
+ key: "setCachePrimer",
34772
+ value: function setCachePrimer(primerFn) {
34773
+ if (typeof primerFn !== 'function') {
34774
+ console.warn('⚠️ Cache primer must be a function');
34775
+ return;
34776
+ }
34777
+ this.cachePrimer = primerFn;
34778
+ console.log('✅ Cache primer function set');
34779
+ }
34780
+
34781
+ /**
34782
+ * Prime the cache with the given URLs using the injected primer
34783
+ * @param {Array<string>} urls - Array of URLs to cache
34784
+ * @returns {Promise<Object>} Result of priming operation
34785
+ */
34786
+ }, {
34787
+ key: "primeCache",
34788
+ value: (function () {
34789
+ var _primeCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(urls) {
34790
+ return _regenerator().w(function (_context) {
34791
+ while (1) switch (_context.n) {
34792
+ case 0:
34793
+ if (this.cachePrimer) {
34794
+ _context.n = 1;
34795
+ break;
34796
+ }
34797
+ console.log('ℹ️ No cache primer set, skipping explicit cache priming');
34798
+ return _context.a(2, {
34799
+ success: 0,
34800
+ failed: 0,
34801
+ skipped: true
34802
+ });
34803
+ case 1:
34804
+ console.log('🔄 Delegating to injected cache primer...', urls.length, 'urls');
34805
+ return _context.a(2, this.cachePrimer(urls));
34806
+ }
34807
+ }, _callee, this);
34808
+ }));
34809
+ function primeCache(_x) {
34810
+ return _primeCache.apply(this, arguments);
34811
+ }
34812
+ return primeCache;
34813
+ }()
34726
34814
  /**
34727
34815
  * Set all managers and utilities on the scene viewer instance
34728
34816
  * @returns {boolean} True if attachment was successful, false otherwise
@@ -34734,6 +34822,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34734
34822
  * console.log('Managers and utilities attached to component');
34735
34823
  * }
34736
34824
  */
34825
+ )
34737
34826
  }, {
34738
34827
  key: "attachToComponent",
34739
34828
  value: function attachToComponent() {
@@ -34775,12 +34864,12 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34775
34864
  }, {
34776
34865
  key: "setImportedSceneData",
34777
34866
  value: (function () {
34778
- var _setImportedSceneData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(sceneData) {
34867
+ var _setImportedSceneData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(sceneData) {
34779
34868
  var _this$importedSceneDa, _this$importedSceneDa2;
34780
- return _regenerator().w(function (_context) {
34781
- while (1) switch (_context.n) {
34869
+ return _regenerator().w(function (_context2) {
34870
+ while (1) switch (_context2.n) {
34782
34871
  case 0:
34783
- _context.n = 1;
34872
+ _context2.n = 1;
34784
34873
  return this.internals.clearSceneComponents();
34785
34874
  case 1:
34786
34875
  this.importedSceneData = _objectSpread2({}, sceneData);
@@ -34793,11 +34882,11 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34793
34882
  // Reset component counter based on imported components to avoid ID conflicts
34794
34883
  this.internals.resetComponentCounter();
34795
34884
  case 2:
34796
- return _context.a(2);
34885
+ return _context2.a(2);
34797
34886
  }
34798
- }, _callee, this);
34887
+ }, _callee2, this);
34799
34888
  }));
34800
- function setImportedSceneData(_x) {
34889
+ function setImportedSceneData(_x2) {
34801
34890
  return _setImportedSceneData.apply(this, arguments);
34802
34891
  }
34803
34892
  return setImportedSceneData;
@@ -35703,41 +35792,41 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35703
35792
  }, {
35704
35793
  key: "getComponents",
35705
35794
  value: (function () {
35706
- var _getComponents = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
35795
+ var _getComponents = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
35707
35796
  var options,
35708
35797
  validation,
35709
35798
  enhancedOptions,
35710
- _args2 = arguments,
35799
+ _args3 = arguments,
35711
35800
  _t;
35712
- return _regenerator().w(function (_context2) {
35713
- while (1) switch (_context2.n) {
35801
+ return _regenerator().w(function (_context3) {
35802
+ while (1) switch (_context3.n) {
35714
35803
  case 0:
35715
- options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
35804
+ options = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
35716
35805
  // Validate filter options using centralized validator
35717
35806
  validation = this.internals.validator.validateComponentFilter(options);
35718
35807
  if (validation.isValid) {
35719
- _context2.n = 1;
35808
+ _context3.n = 1;
35720
35809
  break;
35721
35810
  }
35722
35811
  console.warn('⚠️ getComponents(): Invalid filter options provided:', validation.message);
35723
- return _context2.a(2, []);
35812
+ return _context3.a(2, []);
35724
35813
  case 1:
35725
- _context2.p = 1;
35814
+ _context3.p = 1;
35726
35815
  // Always include metadata
35727
35816
  enhancedOptions = _objectSpread2(_objectSpread2({}, options), {}, {
35728
35817
  includeMetadata: true
35729
35818
  });
35730
- _context2.n = 2;
35819
+ _context3.n = 2;
35731
35820
  return this.managers.componentDataManager.getDictionaryComponents(enhancedOptions);
35732
35821
  case 2:
35733
- return _context2.a(2, _context2.v);
35822
+ return _context3.a(2, _context3.v);
35734
35823
  case 3:
35735
- _context2.p = 3;
35736
- _t = _context2.v;
35824
+ _context3.p = 3;
35825
+ _t = _context3.v;
35737
35826
  console.error('❌ getDictionaryComponents(): Error retrieving available components:', _t);
35738
- return _context2.a(2, []);
35827
+ return _context3.a(2, []);
35739
35828
  }
35740
- }, _callee2, this, [[1, 3]]);
35829
+ }, _callee3, this, [[1, 3]]);
35741
35830
  }));
35742
35831
  function getComponents() {
35743
35832
  return _getComponents.apply(this, arguments);
@@ -35840,25 +35929,25 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35840
35929
  }, {
35841
35930
  key: "extendComponentDictionary",
35842
35931
  value: (function () {
35843
- var _extendComponentDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(additionalComponents) {
35844
- return _regenerator().w(function (_context3) {
35845
- while (1) switch (_context3.n) {
35932
+ var _extendComponentDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(additionalComponents) {
35933
+ return _regenerator().w(function (_context4) {
35934
+ while (1) switch (_context4.n) {
35846
35935
  case 0:
35847
35936
  if (this.managers.componentDataManager) {
35848
- _context3.n = 1;
35937
+ _context4.n = 1;
35849
35938
  break;
35850
35939
  }
35851
35940
  console.warn('⚠️ extendComponentDictionary(): Component data manager not available');
35852
- return _context3.a(2, false);
35941
+ return _context4.a(2, false);
35853
35942
  case 1:
35854
- _context3.n = 2;
35943
+ _context4.n = 2;
35855
35944
  return this.managers.componentDataManager.extendComponentDictionary(additionalComponents);
35856
35945
  case 2:
35857
- return _context3.a(2, _context3.v);
35946
+ return _context4.a(2, _context4.v);
35858
35947
  }
35859
- }, _callee3, this);
35948
+ }, _callee4, this);
35860
35949
  }));
35861
- function extendComponentDictionary(_x2) {
35950
+ function extendComponentDictionary(_x3) {
35862
35951
  return _extendComponentDictionary.apply(this, arguments);
35863
35952
  }
35864
35953
  return extendComponentDictionary;
@@ -35879,23 +35968,23 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35879
35968
  }, {
35880
35969
  key: "removeS3Components",
35881
35970
  value: (function () {
35882
- var _removeS3Components = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
35883
- return _regenerator().w(function (_context4) {
35884
- while (1) switch (_context4.n) {
35971
+ var _removeS3Components = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
35972
+ return _regenerator().w(function (_context5) {
35973
+ while (1) switch (_context5.n) {
35885
35974
  case 0:
35886
35975
  if (this.managers.componentDataManager) {
35887
- _context4.n = 1;
35976
+ _context5.n = 1;
35888
35977
  break;
35889
35978
  }
35890
35979
  console.warn('⚠️ removeS3Components(): Component data manager not available');
35891
- return _context4.a(2, false);
35980
+ return _context5.a(2, false);
35892
35981
  case 1:
35893
- _context4.n = 2;
35982
+ _context5.n = 2;
35894
35983
  return this.managers.componentDataManager.removeS3Components();
35895
35984
  case 2:
35896
- return _context4.a(2, _context4.v);
35985
+ return _context5.a(2, _context5.v);
35897
35986
  }
35898
- }, _callee4, this);
35987
+ }, _callee5, this);
35899
35988
  }));
35900
35989
  function removeS3Components() {
35901
35990
  return _removeS3Components.apply(this, arguments);
@@ -35919,25 +36008,25 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35919
36008
  }, {
35920
36009
  key: "removeComponentFromDictionary",
35921
36010
  value: (function () {
35922
- var _removeComponentFromDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(componentKey) {
35923
- return _regenerator().w(function (_context5) {
35924
- while (1) switch (_context5.n) {
36011
+ var _removeComponentFromDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(componentKey) {
36012
+ return _regenerator().w(function (_context6) {
36013
+ while (1) switch (_context6.n) {
35925
36014
  case 0:
35926
36015
  if (this.managers.componentDataManager) {
35927
- _context5.n = 1;
36016
+ _context6.n = 1;
35928
36017
  break;
35929
36018
  }
35930
36019
  console.warn('⚠️ removeComponentFromDictionary(): Component data manager not available');
35931
- return _context5.a(2, false);
36020
+ return _context6.a(2, false);
35932
36021
  case 1:
35933
- _context5.n = 2;
36022
+ _context6.n = 2;
35934
36023
  return this.managers.componentDataManager.removeComponentFromDictionary(componentKey);
35935
36024
  case 2:
35936
- return _context5.a(2, _context5.v);
36025
+ return _context6.a(2, _context6.v);
35937
36026
  }
35938
- }, _callee5, this);
36027
+ }, _callee6, this);
35939
36028
  }));
35940
- function removeComponentFromDictionary(_x3) {
36029
+ function removeComponentFromDictionary(_x4) {
35941
36030
  return _removeComponentFromDictionary.apply(this, arguments);
35942
36031
  }
35943
36032
  return removeComponentFromDictionary;
@@ -36139,51 +36228,51 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36139
36228
  }, {
36140
36229
  key: "initialize2DViewport",
36141
36230
  value: function () {
36142
- var _initialize2DViewport = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(container) {
36231
+ var _initialize2DViewport = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(container) {
36143
36232
  var viewType,
36144
36233
  instanceKey,
36145
36234
  success,
36146
- _args6 = arguments,
36235
+ _args7 = arguments,
36147
36236
  _t2;
36148
- return _regenerator().w(function (_context6) {
36149
- while (1) switch (_context6.n) {
36237
+ return _regenerator().w(function (_context7) {
36238
+ while (1) switch (_context7.n) {
36150
36239
  case 0:
36151
- viewType = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : 'top';
36152
- instanceKey = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : null;
36240
+ viewType = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 'top';
36241
+ instanceKey = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
36153
36242
  if (container) {
36154
- _context6.n = 1;
36243
+ _context7.n = 1;
36155
36244
  break;
36156
36245
  }
36157
36246
  console.warn('⚠️ initialize2DViewport(): No container provided');
36158
- return _context6.a(2, false);
36247
+ return _context7.a(2, false);
36159
36248
  case 1:
36160
36249
  if (this.managers.viewport2DManager) {
36161
- _context6.n = 2;
36250
+ _context7.n = 2;
36162
36251
  break;
36163
36252
  }
36164
36253
  console.warn('⚠️ initialize2DViewport(): Viewport2D manager not available');
36165
- return _context6.a(2, false);
36254
+ return _context7.a(2, false);
36166
36255
  case 2:
36167
- _context6.p = 2;
36168
- _context6.n = 3;
36256
+ _context7.p = 2;
36257
+ _context7.n = 3;
36169
36258
  return this.managers.viewport2DManager.initialize(container, viewType, instanceKey);
36170
36259
  case 3:
36171
- success = _context6.v;
36260
+ success = _context7.v;
36172
36261
  if (success) {
36173
36262
  console.log("\u2705 2D viewport initialized successfully (".concat(viewType, " view, key: ").concat(instanceKey || viewType, ")"));
36174
36263
  } else {
36175
36264
  console.warn("\u26A0\uFE0F Failed to initialize 2D viewport (".concat(viewType, " view)"));
36176
36265
  }
36177
- return _context6.a(2, success);
36266
+ return _context7.a(2, success);
36178
36267
  case 4:
36179
- _context6.p = 4;
36180
- _t2 = _context6.v;
36268
+ _context7.p = 4;
36269
+ _t2 = _context7.v;
36181
36270
  console.error('❌ initialize2DViewport(): Error initializing 2D viewport:', _t2);
36182
- return _context6.a(2, false);
36271
+ return _context7.a(2, false);
36183
36272
  }
36184
- }, _callee6, this, [[2, 4]]);
36273
+ }, _callee7, this, [[2, 4]]);
36185
36274
  }));
36186
- function initialize2DViewport(_x4) {
36275
+ function initialize2DViewport(_x5) {
36187
36276
  return _initialize2DViewport.apply(this, arguments);
36188
36277
  }
36189
36278
  return initialize2DViewport;
@@ -36329,7 +36418,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36329
36418
  }, {
36330
36419
  key: "initializeModelPreloading",
36331
36420
  value: (function () {
36332
- var _initializeModelPreloading = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
36421
+ var _initializeModelPreloading = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
36333
36422
  var basePath,
36334
36423
  normalizedBasePath,
36335
36424
  dictionaryPath,
@@ -36338,13 +36427,13 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36338
36427
  componentDictionary,
36339
36428
  _modelPreloader2,
36340
36429
  progress,
36341
- _args7 = arguments,
36430
+ _args8 = arguments,
36342
36431
  _t3;
36343
- return _regenerator().w(function (_context7) {
36344
- while (1) switch (_context7.n) {
36432
+ return _regenerator().w(function (_context8) {
36433
+ while (1) switch (_context8.n) {
36345
36434
  case 0:
36346
- basePath = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : '/library/';
36347
- _context7.p = 1;
36435
+ basePath = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : '/library/';
36436
+ _context8.p = 1;
36348
36437
  // Ensure basePath ends with a slash
36349
36438
  normalizedBasePath = basePath.endsWith('/') ? basePath : "".concat(basePath, "/");
36350
36439
  dictionaryPath = "".concat(normalizedBasePath, "component-dictionary.json");
@@ -36355,39 +36444,39 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36355
36444
  console.log("\uFFFD Models path: ".concat(modelsBasePath));
36356
36445
 
36357
36446
  // Load the component dictionary
36358
- _context7.n = 2;
36447
+ _context8.n = 2;
36359
36448
  return fetch(dictionaryPath);
36360
36449
  case 2:
36361
- response = _context7.v;
36450
+ response = _context8.v;
36362
36451
  if (response.ok) {
36363
- _context7.n = 3;
36452
+ _context8.n = 3;
36364
36453
  break;
36365
36454
  }
36366
36455
  throw new Error("Failed to load component dictionary: ".concat(response.status));
36367
36456
  case 3:
36368
- _context7.n = 4;
36457
+ _context8.n = 4;
36369
36458
  return response.json();
36370
36459
  case 4:
36371
- componentDictionary = _context7.v;
36460
+ componentDictionary = _context8.v;
36372
36461
  console.log('📚 Component dictionary loaded:', Object.keys(componentDictionary));
36373
36462
 
36374
36463
  // Start preloading all models with the specified base path
36375
36464
  _modelPreloader2 = this.getUtility('modelPreloader');
36376
- _context7.n = 5;
36465
+ _context8.n = 5;
36377
36466
  return _modelPreloader2.preloadAllModels(componentDictionary, modelsBasePath);
36378
36467
  case 5:
36379
- progress = _context7.v;
36468
+ progress = _context8.v;
36380
36469
  console.log('🎉 Model preloading completed:', progress);
36381
- return _context7.a(2, progress);
36470
+ return _context8.a(2, progress);
36382
36471
  case 6:
36383
- _context7.p = 6;
36384
- _t3 = _context7.v;
36472
+ _context8.p = 6;
36473
+ _t3 = _context8.v;
36385
36474
  console.error('❌ Failed to initialize model preloading:', _t3);
36386
36475
  throw _t3;
36387
36476
  case 7:
36388
- return _context7.a(2);
36477
+ return _context8.a(2);
36389
36478
  }
36390
- }, _callee7, this, [[1, 6]]);
36479
+ }, _callee8, this, [[1, 6]]);
36391
36480
  }));
36392
36481
  function initializeModelPreloading() {
36393
36482
  return _initializeModelPreloading.apply(this, arguments);
@@ -36404,57 +36493,57 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36404
36493
  }, {
36405
36494
  key: "importScene",
36406
36495
  value: (function () {
36407
- var _importScene = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(jsonData) {
36496
+ var _importScene = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(jsonData) {
36408
36497
  var validation, _t4;
36409
- return _regenerator().w(function (_context8) {
36410
- while (1) switch (_context8.n) {
36498
+ return _regenerator().w(function (_context9) {
36499
+ while (1) switch (_context9.n) {
36411
36500
  case 0:
36412
36501
  if (jsonData) {
36413
- _context8.n = 1;
36502
+ _context9.n = 1;
36414
36503
  break;
36415
36504
  }
36416
36505
  console.error('❌ No JSON data provided for import');
36417
- return _context8.a(2, false);
36506
+ return _context9.a(2, false);
36418
36507
  case 1:
36419
- _context8.p = 1;
36508
+ _context9.p = 1;
36420
36509
  // Validate scene data structure
36421
36510
  validation = this.internals.validateAndAnalyzeSceneData(jsonData);
36422
36511
  if (validation.isValid) {
36423
- _context8.n = 2;
36512
+ _context9.n = 2;
36424
36513
  break;
36425
36514
  }
36426
36515
  console.error('❌ Invalid scene data format:', validation.message);
36427
- return _context8.a(2, false);
36516
+ return _context9.a(2, false);
36428
36517
  case 2:
36429
- _context8.n = 3;
36518
+ _context9.n = 3;
36430
36519
  return this.setImportedSceneData(jsonData);
36431
36520
  case 3:
36432
36521
  if (!(this.sceneViewer && this.sceneViewer.sceneOperationsManager)) {
36433
- _context8.n = 5;
36522
+ _context9.n = 5;
36434
36523
  break;
36435
36524
  }
36436
- _context8.n = 4;
36525
+ _context9.n = 4;
36437
36526
  return this.sceneViewer.sceneOperationsManager.loadSceneFromData(jsonData);
36438
36527
  case 4:
36439
36528
  console.log('✅ Scene imported successfully');
36440
- return _context8.a(2, true);
36529
+ return _context9.a(2, true);
36441
36530
  case 5:
36442
36531
  console.error('❌ SceneViewer not available for scene loading');
36443
- return _context8.a(2, false);
36532
+ return _context9.a(2, false);
36444
36533
  case 6:
36445
- _context8.n = 8;
36534
+ _context9.n = 8;
36446
36535
  break;
36447
36536
  case 7:
36448
- _context8.p = 7;
36449
- _t4 = _context8.v;
36537
+ _context9.p = 7;
36538
+ _t4 = _context9.v;
36450
36539
  console.error('❌ Error importing scene:', _t4);
36451
- return _context8.a(2, false);
36540
+ return _context9.a(2, false);
36452
36541
  case 8:
36453
- return _context8.a(2);
36542
+ return _context9.a(2);
36454
36543
  }
36455
- }, _callee8, this, [[1, 7]]);
36544
+ }, _callee9, this, [[1, 7]]);
36456
36545
  }));
36457
- function importScene(_x5) {
36546
+ function importScene(_x6) {
36458
36547
  return _importScene.apply(this, arguments);
36459
36548
  }
36460
36549
  return importScene;
@@ -36476,33 +36565,33 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36476
36565
  }, {
36477
36566
  key: "exportSceneJSON",
36478
36567
  value: (function () {
36479
- var _exportSceneJSON = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
36568
+ var _exportSceneJSON = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
36480
36569
  var filename,
36481
- _args9 = arguments,
36570
+ _args0 = arguments,
36482
36571
  _t5;
36483
- return _regenerator().w(function (_context9) {
36484
- while (1) switch (_context9.n) {
36572
+ return _regenerator().w(function (_context0) {
36573
+ while (1) switch (_context0.n) {
36485
36574
  case 0:
36486
- filename = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : null;
36575
+ filename = _args0.length > 0 && _args0[0] !== undefined ? _args0[0] : null;
36487
36576
  if (this.managers.sceneExportManager) {
36488
- _context9.n = 1;
36577
+ _context0.n = 1;
36489
36578
  break;
36490
36579
  }
36491
36580
  console.error('❌ Scene export manager not available');
36492
- return _context9.a(2, false);
36581
+ return _context0.a(2, false);
36493
36582
  case 1:
36494
- _context9.p = 1;
36495
- _context9.n = 2;
36583
+ _context0.p = 1;
36584
+ _context0.n = 2;
36496
36585
  return this.managers.sceneExportManager.downloadSceneJSON(filename);
36497
36586
  case 2:
36498
- return _context9.a(2, _context9.v);
36587
+ return _context0.a(2, _context0.v);
36499
36588
  case 3:
36500
- _context9.p = 3;
36501
- _t5 = _context9.v;
36589
+ _context0.p = 3;
36590
+ _t5 = _context0.v;
36502
36591
  console.error('❌ Error exporting scene as JSON:', _t5);
36503
- return _context9.a(2, false);
36592
+ return _context0.a(2, false);
36504
36593
  }
36505
- }, _callee9, this, [[1, 3]]);
36594
+ }, _callee0, this, [[1, 3]]);
36506
36595
  }));
36507
36596
  function exportSceneJSON() {
36508
36597
  return _exportSceneJSON.apply(this, arguments);
@@ -36527,33 +36616,33 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36527
36616
  }, {
36528
36617
  key: "exportSceneGLTF",
36529
36618
  value: (function () {
36530
- var _exportSceneGLTF = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
36619
+ var _exportSceneGLTF = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
36531
36620
  var filename,
36532
- _args0 = arguments,
36621
+ _args1 = arguments,
36533
36622
  _t6;
36534
- return _regenerator().w(function (_context0) {
36535
- while (1) switch (_context0.n) {
36623
+ return _regenerator().w(function (_context1) {
36624
+ while (1) switch (_context1.n) {
36536
36625
  case 0:
36537
- filename = _args0.length > 0 && _args0[0] !== undefined ? _args0[0] : null;
36626
+ filename = _args1.length > 0 && _args1[0] !== undefined ? _args1[0] : null;
36538
36627
  if (this.managers.sceneExportManager) {
36539
- _context0.n = 1;
36628
+ _context1.n = 1;
36540
36629
  break;
36541
36630
  }
36542
36631
  console.error('❌ Scene export manager not available');
36543
- return _context0.a(2, false);
36632
+ return _context1.a(2, false);
36544
36633
  case 1:
36545
- _context0.p = 1;
36546
- _context0.n = 2;
36634
+ _context1.p = 1;
36635
+ _context1.n = 2;
36547
36636
  return this.managers.sceneExportManager.exportSceneAsGLTF(filename, false);
36548
36637
  case 2:
36549
- return _context0.a(2, _context0.v);
36638
+ return _context1.a(2, _context1.v);
36550
36639
  case 3:
36551
- _context0.p = 3;
36552
- _t6 = _context0.v;
36640
+ _context1.p = 3;
36641
+ _t6 = _context1.v;
36553
36642
  console.error('❌ Error exporting scene as GLTF:', _t6);
36554
- return _context0.a(2, false);
36643
+ return _context1.a(2, false);
36555
36644
  }
36556
- }, _callee0, this, [[1, 3]]);
36645
+ }, _callee1, this, [[1, 3]]);
36557
36646
  }));
36558
36647
  function exportSceneGLTF() {
36559
36648
  return _exportSceneGLTF.apply(this, arguments);
@@ -36579,33 +36668,33 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36579
36668
  }, {
36580
36669
  key: "exportSceneGLB",
36581
36670
  value: (function () {
36582
- var _exportSceneGLB = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
36671
+ var _exportSceneGLB = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
36583
36672
  var filename,
36584
- _args1 = arguments,
36673
+ _args10 = arguments,
36585
36674
  _t7;
36586
- return _regenerator().w(function (_context1) {
36587
- while (1) switch (_context1.n) {
36675
+ return _regenerator().w(function (_context10) {
36676
+ while (1) switch (_context10.n) {
36588
36677
  case 0:
36589
- filename = _args1.length > 0 && _args1[0] !== undefined ? _args1[0] : null;
36678
+ filename = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : null;
36590
36679
  if (this.managers.sceneExportManager) {
36591
- _context1.n = 1;
36680
+ _context10.n = 1;
36592
36681
  break;
36593
36682
  }
36594
36683
  console.error('❌ Scene export manager not available');
36595
- return _context1.a(2, false);
36684
+ return _context10.a(2, false);
36596
36685
  case 1:
36597
- _context1.p = 1;
36598
- _context1.n = 2;
36686
+ _context10.p = 1;
36687
+ _context10.n = 2;
36599
36688
  return this.managers.sceneExportManager.exportSceneAsGLB(filename);
36600
36689
  case 2:
36601
- return _context1.a(2, _context1.v);
36690
+ return _context10.a(2, _context10.v);
36602
36691
  case 3:
36603
- _context1.p = 3;
36604
- _t7 = _context1.v;
36692
+ _context10.p = 3;
36693
+ _t7 = _context10.v;
36605
36694
  console.error('❌ Error exporting scene as GLB:', _t7);
36606
- return _context1.a(2, false);
36695
+ return _context10.a(2, false);
36607
36696
  }
36608
- }, _callee1, this, [[1, 3]]);
36697
+ }, _callee10, this, [[1, 3]]);
36609
36698
  }));
36610
36699
  function exportSceneGLB() {
36611
36700
  return _exportSceneGLB.apply(this, arguments);
@@ -36644,18 +36733,18 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
36644
36733
  }, {
36645
36734
  key: "loadSceneFromData",
36646
36735
  value: (function () {
36647
- var _loadSceneFromData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(sceneData) {
36648
- return _regenerator().w(function (_context10) {
36649
- while (1) switch (_context10.n) {
36736
+ var _loadSceneFromData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(sceneData) {
36737
+ return _regenerator().w(function (_context11) {
36738
+ while (1) switch (_context11.n) {
36650
36739
  case 0:
36651
- _context10.n = 1;
36740
+ _context11.n = 1;
36652
36741
  return this.setImportedSceneData(sceneData);
36653
36742
  case 1:
36654
- return _context10.a(2, true);
36743
+ return _context11.a(2, true);
36655
36744
  }
36656
- }, _callee10, this);
36745
+ }, _callee11, this);
36657
36746
  }));
36658
- function loadSceneFromData(_x6) {
36747
+ function loadSceneFromData(_x7) {
36659
36748
  return _loadSceneFromData.apply(this, arguments);
36660
36749
  }
36661
36750
  return loadSceneFromData;
@@ -38005,6 +38094,1078 @@ var SceneHierarchyManager = /*#__PURE__*/function (_BaseDisposable) {
38005
38094
  }]);
38006
38095
  }(BaseDisposable);
38007
38096
 
38097
+ /**
38098
+ * Generic Cache Management using Browser Cache API
38099
+ * Framework-agnostic implementation of caching logic
38100
+ */
38101
+
38102
+ // Time constants
38103
+ var SECOND = 1000;
38104
+ var MINUTE = 60 * SECOND;
38105
+ var HOUR = 60 * MINUTE;
38106
+ var DAY = 24 * HOUR;
38107
+ var CACHE_EXPIRY = {
38108
+ MODELS: 7 * DAY,
38109
+ TEXTURES: 7 * DAY,
38110
+ JSON: 24 * HOUR,
38111
+ COMPONENT_DICTIONARY: 24 * HOUR,
38112
+ SCENE_DATA: 12 * HOUR,
38113
+ THUMBNAILS: Infinity,
38114
+ SKYBOXES: 7 * DAY,
38115
+ USER_CONTENT: 6 * HOUR,
38116
+ TEMPORARY: 1 * HOUR,
38117
+ DEFAULT: 24 * HOUR
38118
+ };
38119
+ var CACHE_NAME_PREFIX = 'central-plant-s3-cache-v1';
38120
+ var CacheManager = /*#__PURE__*/function () {
38121
+ function CacheManager() {
38122
+ _classCallCheck(this, CacheManager);
38123
+ this.stats = {
38124
+ hits: 0,
38125
+ misses: 0,
38126
+ errors: 0,
38127
+ totalBytesServed: 0,
38128
+ totalBytesCached: 0,
38129
+ startTime: Date.now()
38130
+ };
38131
+ this.config = {
38132
+ // Default user provider returns null (anonymous)
38133
+ getUser: function () {
38134
+ var _getUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
38135
+ return _regenerator().w(function (_context) {
38136
+ while (1) switch (_context.n) {
38137
+ case 0:
38138
+ return _context.a(2, null);
38139
+ }
38140
+ }, _callee);
38141
+ }));
38142
+ function getUser() {
38143
+ return _getUser.apply(this, arguments);
38144
+ }
38145
+ return getUser;
38146
+ }(),
38147
+ // Default error logger
38148
+ onError: function onError(error) {
38149
+ return console.error('CacheManager Error:', error);
38150
+ }
38151
+ };
38152
+ }
38153
+
38154
+ /**
38155
+ * Configure the cache manager
38156
+ */
38157
+ return _createClass(CacheManager, [{
38158
+ key: "configure",
38159
+ value: function configure() {
38160
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38161
+ this.config = _objectSpread2(_objectSpread2({}, this.config), options);
38162
+ }
38163
+
38164
+ /**
38165
+ * Get cache expiry for a specific file path
38166
+ */
38167
+ }, {
38168
+ key: "getExpiryForPath",
38169
+ value: function getExpiryForPath(path) {
38170
+ var assetType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
38171
+ if (assetType && CACHE_EXPIRY[assetType.toUpperCase()]) {
38172
+ return CACHE_EXPIRY[assetType.toUpperCase()];
38173
+ }
38174
+ var lowerPath = path ? path.toLowerCase() : '';
38175
+ if (lowerPath.includes('/models/') || lowerPath.endsWith('.glb') || lowerPath.endsWith('.gltf')) {
38176
+ return CACHE_EXPIRY.MODELS;
38177
+ }
38178
+ if (lowerPath.includes('/textures/') || lowerPath.endsWith('.jpg') || lowerPath.endsWith('.png') || lowerPath.endsWith('.webp')) {
38179
+ return CACHE_EXPIRY.TEXTURES;
38180
+ }
38181
+ if (lowerPath.includes('/thumbnails/')) {
38182
+ return CACHE_EXPIRY.THUMBNAILS;
38183
+ }
38184
+ if (lowerPath.includes('/skyboxes/') || lowerPath.endsWith('.hdr')) {
38185
+ return CACHE_EXPIRY.SKYBOXES;
38186
+ }
38187
+ if (lowerPath.includes('component-dictionary')) {
38188
+ return CACHE_EXPIRY.COMPONENT_DICTIONARY;
38189
+ }
38190
+ if (lowerPath.endsWith('.json')) {
38191
+ return CACHE_EXPIRY.JSON;
38192
+ }
38193
+ return CACHE_EXPIRY.DEFAULT;
38194
+ }
38195
+
38196
+ /**
38197
+ * Get or open the cache handle efficiently
38198
+ */
38199
+ }, {
38200
+ key: "_getCacheHandle",
38201
+ value: (function () {
38202
+ var _getCacheHandle2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(cacheName) {
38203
+ return _regenerator().w(function (_context2) {
38204
+ while (1) switch (_context2.n) {
38205
+ case 0:
38206
+ if (!(this._activeCacheName === cacheName && this._activeCacheHandle)) {
38207
+ _context2.n = 1;
38208
+ break;
38209
+ }
38210
+ return _context2.a(2, this._activeCacheHandle);
38211
+ case 1:
38212
+ // If we are switching caches, close/drop reference to the old one (GC handles it, but good practice)
38213
+ this._activeCacheName = cacheName;
38214
+ _context2.n = 2;
38215
+ return caches.open(cacheName);
38216
+ case 2:
38217
+ this._activeCacheHandle = _context2.v;
38218
+ return _context2.a(2, this._activeCacheHandle);
38219
+ }
38220
+ }, _callee2, this);
38221
+ }));
38222
+ function _getCacheHandle(_x) {
38223
+ return _getCacheHandle2.apply(this, arguments);
38224
+ }
38225
+ return _getCacheHandle;
38226
+ }()
38227
+ /**
38228
+ * Get the cache name for the current user
38229
+ * Memoized to prevent excessive Auth calls
38230
+ */
38231
+ /**
38232
+ * Resets the identity, forcing a re-fetch of the user/cache name on next access
38233
+ */
38234
+ )
38235
+ }, {
38236
+ key: "resetIdentity",
38237
+ value: function resetIdentity() {
38238
+ this._cachedCacheName = null;
38239
+ }
38240
+
38241
+ /**
38242
+ * Get the cache name for the current user
38243
+ * Memoized indefinitely until resetIdentity() is called
38244
+ */
38245
+ }, {
38246
+ key: "getCacheName",
38247
+ value: (function () {
38248
+ var _getCacheName = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
38249
+ var user, cacheName, _user$attributes, userId, sanitizedUserId, _t;
38250
+ return _regenerator().w(function (_context3) {
38251
+ while (1) switch (_context3.n) {
38252
+ case 0:
38253
+ if (!this._cachedCacheName) {
38254
+ _context3.n = 1;
38255
+ break;
38256
+ }
38257
+ return _context3.a(2, this._cachedCacheName);
38258
+ case 1:
38259
+ _context3.p = 1;
38260
+ _context3.n = 2;
38261
+ return this.config.getUser();
38262
+ case 2:
38263
+ user = _context3.v;
38264
+ if (!user) {
38265
+ cacheName = "".concat(CACHE_NAME_PREFIX, "-anonymous");
38266
+ } else {
38267
+ userId = typeof user === 'string' ? user : user.username || ((_user$attributes = user.attributes) === null || _user$attributes === void 0 ? void 0 : _user$attributes.sub) || 'anonymous';
38268
+ sanitizedUserId = userId.replace(/[^a-zA-Z0-9-]/g, '-');
38269
+ cacheName = "".concat(CACHE_NAME_PREFIX, "-user-").concat(sanitizedUserId);
38270
+ }
38271
+ this._cachedCacheName = cacheName;
38272
+ return _context3.a(2, cacheName);
38273
+ case 3:
38274
+ _context3.p = 3;
38275
+ _t = _context3.v;
38276
+ console.warn('Failed to get user for cache partition, using anonymous:', _t);
38277
+ return _context3.a(2, "".concat(CACHE_NAME_PREFIX, "-anonymous"));
38278
+ }
38279
+ }, _callee3, this, [[1, 3]]);
38280
+ }));
38281
+ function getCacheName() {
38282
+ return _getCacheName.apply(this, arguments);
38283
+ }
38284
+ return getCacheName;
38285
+ }()
38286
+ /**
38287
+ * Execute a cache operation
38288
+ */
38289
+ )
38290
+ }, {
38291
+ key: "execute",
38292
+ value: (function () {
38293
+ var _execute = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref) {
38294
+ var cacheKey, sourceKey, expiryMs, fetcher, processor, _ref$metadata, metadata, cacheName, cache, cachedResponse, cachedTime, age, result, fetchResult, blobOrJson, contentType, contentSize, responseBody, headers, cacheResponse, fallbackResult, _t2;
38295
+ return _regenerator().w(function (_context4) {
38296
+ while (1) switch (_context4.n) {
38297
+ case 0:
38298
+ cacheKey = _ref.cacheKey, sourceKey = _ref.sourceKey, expiryMs = _ref.expiryMs, fetcher = _ref.fetcher, processor = _ref.processor, _ref$metadata = _ref.metadata, metadata = _ref$metadata === void 0 ? {} : _ref$metadata, _ref.logType;
38299
+ _context4.p = 1;
38300
+ _context4.n = 2;
38301
+ return this.getCacheName();
38302
+ case 2:
38303
+ cacheName = _context4.v;
38304
+ _context4.n = 3;
38305
+ return this._getCacheHandle(cacheName);
38306
+ case 3:
38307
+ cache = _context4.v;
38308
+ _context4.n = 4;
38309
+ return cache.match(cacheKey);
38310
+ case 4:
38311
+ cachedResponse = _context4.v;
38312
+ if (!cachedResponse) {
38313
+ _context4.n = 7;
38314
+ break;
38315
+ }
38316
+ cachedTime = cachedResponse.headers.get('x-cached-time');
38317
+ age = Date.now() - parseInt(cachedTime || '0');
38318
+ if (!(age < expiryMs)) {
38319
+ _context4.n = 6;
38320
+ break;
38321
+ }
38322
+ _context4.n = 5;
38323
+ return processor(cachedResponse.clone());
38324
+ case 5:
38325
+ result = _context4.v;
38326
+ this.stats.hits++;
38327
+ result instanceof Blob ? result.size : 0;
38328
+ if (result instanceof Blob) this.stats.totalBytesServed += result.size;
38329
+ return _context4.a(2, result);
38330
+ case 6:
38331
+ _context4.n = 7;
38332
+ return cache.delete(cacheKey);
38333
+ case 7:
38334
+ this.stats.misses++;
38335
+ _context4.n = 8;
38336
+ return fetcher();
38337
+ case 8:
38338
+ fetchResult = _context4.v;
38339
+ blobOrJson = fetchResult;
38340
+ if (!(fetchResult instanceof Response)) {
38341
+ _context4.n = 11;
38342
+ break;
38343
+ }
38344
+ if (fetchResult.ok) {
38345
+ _context4.n = 9;
38346
+ break;
38347
+ }
38348
+ throw new Error("Fetch failed: ".concat(fetchResult.status));
38349
+ case 9:
38350
+ _context4.n = 10;
38351
+ return processor(fetchResult.clone());
38352
+ case 10:
38353
+ blobOrJson = _context4.v;
38354
+ case 11:
38355
+ contentType = 'application/octet-stream';
38356
+ contentSize = 0;
38357
+ responseBody = blobOrJson;
38358
+ if (blobOrJson instanceof Blob) {
38359
+ contentType = blobOrJson.type;
38360
+ contentSize = blobOrJson.size;
38361
+ this.stats.totalBytesCached += contentSize;
38362
+ this.stats.totalBytesServed += contentSize;
38363
+ } else {
38364
+ contentType = 'application/json';
38365
+ responseBody = JSON.stringify(blobOrJson);
38366
+ contentSize = responseBody.length;
38367
+ }
38368
+ headers = new Headers(_objectSpread2({
38369
+ 'Content-Type': contentType,
38370
+ 'x-cached-time': Date.now().toString(),
38371
+ 'x-source-key': sourceKey || ''
38372
+ }, metadata));
38373
+ cacheResponse = new Response(responseBody, {
38374
+ headers: headers
38375
+ });
38376
+ _context4.n = 12;
38377
+ return cache.put(cacheKey, cacheResponse);
38378
+ case 12:
38379
+ return _context4.a(2, blobOrJson);
38380
+ case 13:
38381
+ _context4.p = 13;
38382
+ _t2 = _context4.v;
38383
+ this.stats.errors++;
38384
+ this.config.onError(_t2);
38385
+
38386
+ // Fallback
38387
+ _context4.p = 14;
38388
+ _context4.n = 15;
38389
+ return fetcher();
38390
+ case 15:
38391
+ fallbackResult = _context4.v;
38392
+ if (!(fallbackResult instanceof Response)) {
38393
+ _context4.n = 16;
38394
+ break;
38395
+ }
38396
+ return _context4.a(2, processor(fallbackResult));
38397
+ case 16:
38398
+ return _context4.a(2, fallbackResult);
38399
+ case 17:
38400
+ _context4.p = 17;
38401
+ _context4.v;
38402
+ throw _t2;
38403
+ case 18:
38404
+ return _context4.a(2);
38405
+ }
38406
+ }, _callee4, this, [[14, 17], [1, 13]]);
38407
+ }));
38408
+ function execute(_x2) {
38409
+ return _execute.apply(this, arguments);
38410
+ }
38411
+ return execute;
38412
+ }())
38413
+ }, {
38414
+ key: "getGlobalStats",
38415
+ value: function getGlobalStats() {
38416
+ var uptime = Date.now() - this.stats.startTime;
38417
+ return _objectSpread2(_objectSpread2({}, this.stats), {}, {
38418
+ hitRate: this.stats.hits + this.stats.misses > 0 ? (this.stats.hits / (this.stats.hits + this.stats.misses) * 100).toFixed(1) + '%' : '0%',
38419
+ totalMBServed: (this.stats.totalBytesServed / 1024 / 1024).toFixed(2),
38420
+ totalMBCached: (this.stats.totalBytesCached / 1024 / 1024).toFixed(2),
38421
+ uptimeMinutes: (uptime / 1000 / 60).toFixed(1)
38422
+ });
38423
+ }
38424
+ }, {
38425
+ key: "resetStats",
38426
+ value: function resetStats() {
38427
+ this.stats = {
38428
+ hits: 0,
38429
+ misses: 0,
38430
+ errors: 0,
38431
+ totalBytesServed: 0,
38432
+ totalBytesCached: 0,
38433
+ startTime: Date.now()
38434
+ };
38435
+ }
38436
+ }, {
38437
+ key: "clearCache",
38438
+ value: function () {
38439
+ var _clearCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
38440
+ var specificKey,
38441
+ clearAllUsers,
38442
+ cacheName,
38443
+ cache,
38444
+ keys,
38445
+ _iterator,
38446
+ _step,
38447
+ req,
38448
+ cacheNames,
38449
+ appCaches,
38450
+ _iterator2,
38451
+ _step2,
38452
+ name,
38453
+ _cacheName,
38454
+ _args5 = arguments,
38455
+ _t4,
38456
+ _t5,
38457
+ _t6;
38458
+ return _regenerator().w(function (_context5) {
38459
+ while (1) switch (_context5.n) {
38460
+ case 0:
38461
+ specificKey = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : null;
38462
+ clearAllUsers = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : false;
38463
+ _context5.p = 1;
38464
+ if (!specificKey) {
38465
+ _context5.n = 12;
38466
+ break;
38467
+ }
38468
+ _context5.n = 2;
38469
+ return this.getCacheName();
38470
+ case 2:
38471
+ cacheName = _context5.v;
38472
+ _context5.n = 3;
38473
+ return caches.open(cacheName);
38474
+ case 3:
38475
+ cache = _context5.v;
38476
+ _context5.n = 4;
38477
+ return cache.keys();
38478
+ case 4:
38479
+ keys = _context5.v;
38480
+ _iterator = _createForOfIteratorHelper(keys);
38481
+ _context5.p = 5;
38482
+ _iterator.s();
38483
+ case 6:
38484
+ if ((_step = _iterator.n()).done) {
38485
+ _context5.n = 8;
38486
+ break;
38487
+ }
38488
+ req = _step.value;
38489
+ if (!req.url.includes(specificKey)) {
38490
+ _context5.n = 7;
38491
+ break;
38492
+ }
38493
+ _context5.n = 7;
38494
+ return cache.delete(req);
38495
+ case 7:
38496
+ _context5.n = 6;
38497
+ break;
38498
+ case 8:
38499
+ _context5.n = 10;
38500
+ break;
38501
+ case 9:
38502
+ _context5.p = 9;
38503
+ _t4 = _context5.v;
38504
+ _iterator.e(_t4);
38505
+ case 10:
38506
+ _context5.p = 10;
38507
+ _iterator.f();
38508
+ return _context5.f(10);
38509
+ case 11:
38510
+ _context5.n = 23;
38511
+ break;
38512
+ case 12:
38513
+ if (!clearAllUsers) {
38514
+ _context5.n = 21;
38515
+ break;
38516
+ }
38517
+ _context5.n = 13;
38518
+ return caches.keys();
38519
+ case 13:
38520
+ cacheNames = _context5.v;
38521
+ appCaches = cacheNames.filter(function (name) {
38522
+ return name.startsWith(CACHE_NAME_PREFIX);
38523
+ });
38524
+ _iterator2 = _createForOfIteratorHelper(appCaches);
38525
+ _context5.p = 14;
38526
+ _iterator2.s();
38527
+ case 15:
38528
+ if ((_step2 = _iterator2.n()).done) {
38529
+ _context5.n = 17;
38530
+ break;
38531
+ }
38532
+ name = _step2.value;
38533
+ _context5.n = 16;
38534
+ return caches.delete(name);
38535
+ case 16:
38536
+ _context5.n = 15;
38537
+ break;
38538
+ case 17:
38539
+ _context5.n = 19;
38540
+ break;
38541
+ case 18:
38542
+ _context5.p = 18;
38543
+ _t5 = _context5.v;
38544
+ _iterator2.e(_t5);
38545
+ case 19:
38546
+ _context5.p = 19;
38547
+ _iterator2.f();
38548
+ return _context5.f(19);
38549
+ case 20:
38550
+ _context5.n = 23;
38551
+ break;
38552
+ case 21:
38553
+ _context5.n = 22;
38554
+ return this.getCacheName();
38555
+ case 22:
38556
+ _cacheName = _context5.v;
38557
+ _context5.n = 23;
38558
+ return caches.delete(_cacheName);
38559
+ case 23:
38560
+ return _context5.a(2, true);
38561
+ case 24:
38562
+ _context5.p = 24;
38563
+ _t6 = _context5.v;
38564
+ this.config.onError(_t6);
38565
+ return _context5.a(2, false);
38566
+ }
38567
+ }, _callee5, this, [[14, 18, 19, 20], [5, 9, 10, 11], [1, 24]]);
38568
+ }));
38569
+ function clearCache() {
38570
+ return _clearCache.apply(this, arguments);
38571
+ }
38572
+ return clearCache;
38573
+ }()
38574
+ }, {
38575
+ key: "cleanExpired",
38576
+ value: function () {
38577
+ var _cleanExpired = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
38578
+ var cacheName, cache, keys, count, _iterator3, _step3, request, response, cachedTime, age, sourceKey, expiryMs, _t7, _t8;
38579
+ return _regenerator().w(function (_context6) {
38580
+ while (1) switch (_context6.n) {
38581
+ case 0:
38582
+ _context6.p = 0;
38583
+ _context6.n = 1;
38584
+ return this.getCacheName();
38585
+ case 1:
38586
+ cacheName = _context6.v;
38587
+ _context6.n = 2;
38588
+ return this._getCacheHandle(cacheName);
38589
+ case 2:
38590
+ cache = _context6.v;
38591
+ _context6.n = 3;
38592
+ return cache.keys();
38593
+ case 3:
38594
+ keys = _context6.v;
38595
+ count = 0;
38596
+ _iterator3 = _createForOfIteratorHelper(keys);
38597
+ _context6.p = 4;
38598
+ _iterator3.s();
38599
+ case 5:
38600
+ if ((_step3 = _iterator3.n()).done) {
38601
+ _context6.n = 9;
38602
+ break;
38603
+ }
38604
+ request = _step3.value;
38605
+ _context6.n = 6;
38606
+ return cache.match(request);
38607
+ case 6:
38608
+ response = _context6.v;
38609
+ cachedTime = response.headers.get('x-cached-time');
38610
+ age = Date.now() - parseInt(cachedTime || '0');
38611
+ sourceKey = response.headers.get('x-source-key') || request.url;
38612
+ expiryMs = this.getExpiryForPath(sourceKey);
38613
+ if (!(age > expiryMs)) {
38614
+ _context6.n = 8;
38615
+ break;
38616
+ }
38617
+ _context6.n = 7;
38618
+ return cache.delete(request);
38619
+ case 7:
38620
+ count++;
38621
+ case 8:
38622
+ _context6.n = 5;
38623
+ break;
38624
+ case 9:
38625
+ _context6.n = 11;
38626
+ break;
38627
+ case 10:
38628
+ _context6.p = 10;
38629
+ _t7 = _context6.v;
38630
+ _iterator3.e(_t7);
38631
+ case 11:
38632
+ _context6.p = 11;
38633
+ _iterator3.f();
38634
+ return _context6.f(11);
38635
+ case 12:
38636
+ return _context6.a(2, count);
38637
+ case 13:
38638
+ _context6.p = 13;
38639
+ _t8 = _context6.v;
38640
+ this.config.onError(_t8);
38641
+ return _context6.a(2, 0);
38642
+ }
38643
+ }, _callee6, this, [[4, 10, 11, 12], [0, 13]]);
38644
+ }));
38645
+ function cleanExpired() {
38646
+ return _cleanExpired.apply(this, arguments);
38647
+ }
38648
+ return cleanExpired;
38649
+ }()
38650
+ }, {
38651
+ key: "cleanInvalid",
38652
+ value: function () {
38653
+ var _cleanInvalid = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
38654
+ var cacheName, cache, keys, cleanedCount, _iterator4, _step4, request, url, _t9, _t0;
38655
+ return _regenerator().w(function (_context7) {
38656
+ while (1) switch (_context7.n) {
38657
+ case 0:
38658
+ _context7.p = 0;
38659
+ _context7.n = 1;
38660
+ return this.getCacheName();
38661
+ case 1:
38662
+ cacheName = _context7.v;
38663
+ _context7.n = 2;
38664
+ return this._getCacheHandle(cacheName);
38665
+ case 2:
38666
+ cache = _context7.v;
38667
+ _context7.n = 3;
38668
+ return cache.keys();
38669
+ case 3:
38670
+ keys = _context7.v;
38671
+ cleanedCount = 0;
38672
+ _iterator4 = _createForOfIteratorHelper(keys);
38673
+ _context7.p = 4;
38674
+ _iterator4.s();
38675
+ case 5:
38676
+ if ((_step4 = _iterator4.n()).done) {
38677
+ _context7.n = 8;
38678
+ break;
38679
+ }
38680
+ request = _step4.value;
38681
+ url = request.url;
38682
+ if (!(url.includes('undefined') || url.includes('null') || url.includes('/library/models//'))) {
38683
+ _context7.n = 7;
38684
+ break;
38685
+ }
38686
+ _context7.n = 6;
38687
+ return cache.delete(request);
38688
+ case 6:
38689
+ cleanedCount++;
38690
+ case 7:
38691
+ _context7.n = 5;
38692
+ break;
38693
+ case 8:
38694
+ _context7.n = 10;
38695
+ break;
38696
+ case 9:
38697
+ _context7.p = 9;
38698
+ _t9 = _context7.v;
38699
+ _iterator4.e(_t9);
38700
+ case 10:
38701
+ _context7.p = 10;
38702
+ _iterator4.f();
38703
+ return _context7.f(10);
38704
+ case 11:
38705
+ return _context7.a(2, cleanedCount);
38706
+ case 12:
38707
+ _context7.p = 12;
38708
+ _t0 = _context7.v;
38709
+ this.config.onError(_t0);
38710
+ return _context7.a(2, 0);
38711
+ }
38712
+ }, _callee7, this, [[4, 9, 10, 11], [0, 12]]);
38713
+ }));
38714
+ function cleanInvalid() {
38715
+ return _cleanInvalid.apply(this, arguments);
38716
+ }
38717
+ return cleanInvalid;
38718
+ }()
38719
+ /**
38720
+ * Check if a key exists in cache and is valid
38721
+ */
38722
+ }, {
38723
+ key: "has",
38724
+ value: (function () {
38725
+ var _has = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(cacheKey) {
38726
+ var expiryMs,
38727
+ cacheName,
38728
+ cache,
38729
+ response,
38730
+ cachedTime,
38731
+ age,
38732
+ expiry,
38733
+ _args8 = arguments,
38734
+ _t1;
38735
+ return _regenerator().w(function (_context8) {
38736
+ while (1) switch (_context8.n) {
38737
+ case 0:
38738
+ expiryMs = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : null;
38739
+ _context8.p = 1;
38740
+ _context8.n = 2;
38741
+ return this.getCacheName();
38742
+ case 2:
38743
+ cacheName = _context8.v;
38744
+ _context8.n = 3;
38745
+ return this._getCacheHandle(cacheName);
38746
+ case 3:
38747
+ cache = _context8.v;
38748
+ _context8.n = 4;
38749
+ return cache.match(cacheKey);
38750
+ case 4:
38751
+ response = _context8.v;
38752
+ if (response) {
38753
+ _context8.n = 5;
38754
+ break;
38755
+ }
38756
+ return _context8.a(2, false);
38757
+ case 5:
38758
+ cachedTime = response.headers.get('x-cached-time');
38759
+ age = Date.now() - parseInt(cachedTime || '0');
38760
+ expiry = expiryMs || this.getExpiryForPath(cacheKey);
38761
+ if (!(age < expiry)) {
38762
+ _context8.n = 6;
38763
+ break;
38764
+ }
38765
+ return _context8.a(2, true);
38766
+ case 6:
38767
+ _context8.n = 7;
38768
+ return cache.delete(cacheKey);
38769
+ case 7:
38770
+ return _context8.a(2, false);
38771
+ case 8:
38772
+ _context8.n = 10;
38773
+ break;
38774
+ case 9:
38775
+ _context8.p = 9;
38776
+ _t1 = _context8.v;
38777
+ this.config.onError(_t1);
38778
+ return _context8.a(2, false);
38779
+ case 10:
38780
+ return _context8.a(2);
38781
+ }
38782
+ }, _callee8, this, [[1, 9]]);
38783
+ }));
38784
+ function has(_x3) {
38785
+ return _has.apply(this, arguments);
38786
+ }
38787
+ return has;
38788
+ }()
38789
+ /**
38790
+ * Get a value from cache without fetching (returns null on miss/expiry)
38791
+ */
38792
+ )
38793
+ }, {
38794
+ key: "get",
38795
+ value: (function () {
38796
+ var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(cacheKey) {
38797
+ var expiryMs,
38798
+ processor,
38799
+ cacheName,
38800
+ cache,
38801
+ response,
38802
+ cachedTime,
38803
+ age,
38804
+ expiry,
38805
+ _args0 = arguments,
38806
+ _t10;
38807
+ return _regenerator().w(function (_context0) {
38808
+ while (1) switch (_context0.n) {
38809
+ case 0:
38810
+ expiryMs = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : null;
38811
+ processor = _args0.length > 2 && _args0[2] !== undefined ? _args0[2] : (/*#__PURE__*/function () {
38812
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(r) {
38813
+ return _regenerator().w(function (_context9) {
38814
+ while (1) switch (_context9.n) {
38815
+ case 0:
38816
+ return _context9.a(2, r.json());
38817
+ }
38818
+ }, _callee9);
38819
+ }));
38820
+ return function (_x5) {
38821
+ return _ref2.apply(this, arguments);
38822
+ };
38823
+ }());
38824
+ _context0.p = 1;
38825
+ _context0.n = 2;
38826
+ return this.getCacheName();
38827
+ case 2:
38828
+ cacheName = _context0.v;
38829
+ _context0.n = 3;
38830
+ return this._getCacheHandle(cacheName);
38831
+ case 3:
38832
+ cache = _context0.v;
38833
+ _context0.n = 4;
38834
+ return cache.match(cacheKey);
38835
+ case 4:
38836
+ response = _context0.v;
38837
+ if (response) {
38838
+ _context0.n = 5;
38839
+ break;
38840
+ }
38841
+ return _context0.a(2, null);
38842
+ case 5:
38843
+ cachedTime = response.headers.get('x-cached-time');
38844
+ age = Date.now() - parseInt(cachedTime || '0');
38845
+ expiry = expiryMs || this.getExpiryForPath(cacheKey);
38846
+ if (!(age < expiry)) {
38847
+ _context0.n = 7;
38848
+ break;
38849
+ }
38850
+ this.stats.hits++;
38851
+ _context0.n = 6;
38852
+ return processor(response);
38853
+ case 6:
38854
+ return _context0.a(2, _context0.v);
38855
+ case 7:
38856
+ _context0.n = 8;
38857
+ return cache.delete(cacheKey);
38858
+ case 8:
38859
+ return _context0.a(2, null);
38860
+ case 9:
38861
+ _context0.n = 11;
38862
+ break;
38863
+ case 10:
38864
+ _context0.p = 10;
38865
+ _t10 = _context0.v;
38866
+ this.config.onError(_t10);
38867
+ return _context0.a(2, null);
38868
+ case 11:
38869
+ return _context0.a(2);
38870
+ }
38871
+ }, _callee0, this, [[1, 10]]);
38872
+ }));
38873
+ function get(_x4) {
38874
+ return _get.apply(this, arguments);
38875
+ }
38876
+ return get;
38877
+ }()
38878
+ /**
38879
+ * Delete a specific key from value
38880
+ */
38881
+ )
38882
+ }, {
38883
+ key: "delete",
38884
+ value: (function () {
38885
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(cacheKey) {
38886
+ var cacheName, cache, _t11;
38887
+ return _regenerator().w(function (_context1) {
38888
+ while (1) switch (_context1.n) {
38889
+ case 0:
38890
+ _context1.p = 0;
38891
+ _context1.n = 1;
38892
+ return this.getCacheName();
38893
+ case 1:
38894
+ cacheName = _context1.v;
38895
+ _context1.n = 2;
38896
+ return this._getCacheHandle(cacheName);
38897
+ case 2:
38898
+ cache = _context1.v;
38899
+ _context1.n = 3;
38900
+ return cache.delete(cacheKey);
38901
+ case 3:
38902
+ return _context1.a(2, _context1.v);
38903
+ case 4:
38904
+ _context1.p = 4;
38905
+ _t11 = _context1.v;
38906
+ this.config.onError(_t11);
38907
+ return _context1.a(2, false);
38908
+ }
38909
+ }, _callee1, this, [[0, 4]]);
38910
+ }));
38911
+ function _delete(_x6) {
38912
+ return _delete2.apply(this, arguments);
38913
+ }
38914
+ return _delete;
38915
+ }()
38916
+ /**
38917
+ * Delete a specific named cache (partition)
38918
+ */
38919
+ )
38920
+ }, {
38921
+ key: "deleteCache",
38922
+ value: (function () {
38923
+ var _deleteCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(cacheName) {
38924
+ var _t12;
38925
+ return _regenerator().w(function (_context10) {
38926
+ while (1) switch (_context10.n) {
38927
+ case 0:
38928
+ _context10.p = 0;
38929
+ _context10.n = 1;
38930
+ return caches.delete(cacheName);
38931
+ case 1:
38932
+ return _context10.a(2, _context10.v);
38933
+ case 2:
38934
+ _context10.p = 2;
38935
+ _t12 = _context10.v;
38936
+ this.config.onError(_t12);
38937
+ return _context10.a(2, false);
38938
+ }
38939
+ }, _callee10, this, [[0, 2]]);
38940
+ }));
38941
+ function deleteCache(_x7) {
38942
+ return _deleteCache.apply(this, arguments);
38943
+ }
38944
+ return deleteCache;
38945
+ }())
38946
+ }, {
38947
+ key: "getDetailedStats",
38948
+ value: function () {
38949
+ var _getDetailedStats = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
38950
+ var allUsers,
38951
+ cacheNames,
38952
+ plantCaches,
38953
+ allStats,
38954
+ _iterator5,
38955
+ _step5,
38956
+ _cacheName2,
38957
+ _cache,
38958
+ _keys,
38959
+ _totalSize,
38960
+ _iterator6,
38961
+ _step6,
38962
+ request,
38963
+ response,
38964
+ blob,
38965
+ grandTotal,
38966
+ cacheName,
38967
+ cache,
38968
+ keys,
38969
+ totalSize,
38970
+ items,
38971
+ _iterator7,
38972
+ _step7,
38973
+ _request,
38974
+ _response,
38975
+ _blob,
38976
+ cachedTime,
38977
+ sourceKey,
38978
+ _args11 = arguments,
38979
+ _t13,
38980
+ _t14,
38981
+ _t15,
38982
+ _t16;
38983
+ return _regenerator().w(function (_context11) {
38984
+ while (1) switch (_context11.n) {
38985
+ case 0:
38986
+ allUsers = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : false;
38987
+ _context11.p = 1;
38988
+ if (!allUsers) {
38989
+ _context11.n = 21;
38990
+ break;
38991
+ }
38992
+ _context11.n = 2;
38993
+ return caches.keys();
38994
+ case 2:
38995
+ cacheNames = _context11.v;
38996
+ plantCaches = cacheNames.filter(function (name) {
38997
+ return name.startsWith(CACHE_NAME_PREFIX);
38998
+ });
38999
+ allStats = [];
39000
+ _iterator5 = _createForOfIteratorHelper(plantCaches);
39001
+ _context11.p = 3;
39002
+ _iterator5.s();
39003
+ case 4:
39004
+ if ((_step5 = _iterator5.n()).done) {
39005
+ _context11.n = 17;
39006
+ break;
39007
+ }
39008
+ _cacheName2 = _step5.value;
39009
+ _context11.n = 5;
39010
+ return caches.open(_cacheName2);
39011
+ case 5:
39012
+ _cache = _context11.v;
39013
+ _context11.n = 6;
39014
+ return _cache.keys();
39015
+ case 6:
39016
+ _keys = _context11.v;
39017
+ _totalSize = 0;
39018
+ _iterator6 = _createForOfIteratorHelper(_keys);
39019
+ _context11.p = 7;
39020
+ _iterator6.s();
39021
+ case 8:
39022
+ if ((_step6 = _iterator6.n()).done) {
39023
+ _context11.n = 12;
39024
+ break;
39025
+ }
39026
+ request = _step6.value;
39027
+ _context11.n = 9;
39028
+ return _cache.match(request);
39029
+ case 9:
39030
+ response = _context11.v;
39031
+ _context11.n = 10;
39032
+ return response.blob();
39033
+ case 10:
39034
+ blob = _context11.v;
39035
+ _totalSize += blob.size;
39036
+ case 11:
39037
+ _context11.n = 8;
39038
+ break;
39039
+ case 12:
39040
+ _context11.n = 14;
39041
+ break;
39042
+ case 13:
39043
+ _context11.p = 13;
39044
+ _t13 = _context11.v;
39045
+ _iterator6.e(_t13);
39046
+ case 14:
39047
+ _context11.p = 14;
39048
+ _iterator6.f();
39049
+ return _context11.f(14);
39050
+ case 15:
39051
+ allStats.push({
39052
+ cacheName: _cacheName2,
39053
+ count: _keys.length,
39054
+ totalSize: _totalSize,
39055
+ totalSizeMB: (_totalSize / 1024 / 1024).toFixed(2)
39056
+ });
39057
+ case 16:
39058
+ _context11.n = 4;
39059
+ break;
39060
+ case 17:
39061
+ _context11.n = 19;
39062
+ break;
39063
+ case 18:
39064
+ _context11.p = 18;
39065
+ _t14 = _context11.v;
39066
+ _iterator5.e(_t14);
39067
+ case 19:
39068
+ _context11.p = 19;
39069
+ _iterator5.f();
39070
+ return _context11.f(19);
39071
+ case 20:
39072
+ grandTotal = allStats.reduce(function (sum, stat) {
39073
+ return sum + stat.totalSize;
39074
+ }, 0);
39075
+ return _context11.a(2, {
39076
+ caches: allStats,
39077
+ totalCaches: allStats.length,
39078
+ grandTotalSizeMB: (grandTotal / 1024 / 1024).toFixed(2)
39079
+ });
39080
+ case 21:
39081
+ _context11.n = 22;
39082
+ return this.getCacheName();
39083
+ case 22:
39084
+ cacheName = _context11.v;
39085
+ _context11.n = 23;
39086
+ return caches.open(cacheName);
39087
+ case 23:
39088
+ cache = _context11.v;
39089
+ _context11.n = 24;
39090
+ return cache.keys();
39091
+ case 24:
39092
+ keys = _context11.v;
39093
+ totalSize = 0;
39094
+ items = [];
39095
+ _iterator7 = _createForOfIteratorHelper(keys);
39096
+ _context11.p = 25;
39097
+ _iterator7.s();
39098
+ case 26:
39099
+ if ((_step7 = _iterator7.n()).done) {
39100
+ _context11.n = 30;
39101
+ break;
39102
+ }
39103
+ _request = _step7.value;
39104
+ _context11.n = 27;
39105
+ return cache.match(_request);
39106
+ case 27:
39107
+ _response = _context11.v;
39108
+ _context11.n = 28;
39109
+ return _response.blob();
39110
+ case 28:
39111
+ _blob = _context11.v;
39112
+ cachedTime = _response.headers.get('x-cached-time'); // Try to get key from headers or fallback
39113
+ sourceKey = _response.headers.get('x-source-key') || _response.headers.get('x-s3-key') || _response.headers.get('x-local-path') || _request.url;
39114
+ totalSize += _blob.size;
39115
+ items.push({
39116
+ url: _request.url,
39117
+ sourceKey: sourceKey,
39118
+ size: _blob.size,
39119
+ sizeMB: (_blob.size / 1024 / 1024).toFixed(2),
39120
+ type: _blob.type,
39121
+ cachedTime: parseInt(cachedTime || '0'),
39122
+ age: Date.now() - parseInt(cachedTime || '0')
39123
+ });
39124
+ case 29:
39125
+ _context11.n = 26;
39126
+ break;
39127
+ case 30:
39128
+ _context11.n = 32;
39129
+ break;
39130
+ case 31:
39131
+ _context11.p = 31;
39132
+ _t15 = _context11.v;
39133
+ _iterator7.e(_t15);
39134
+ case 32:
39135
+ _context11.p = 32;
39136
+ _iterator7.f();
39137
+ return _context11.f(32);
39138
+ case 33:
39139
+ return _context11.a(2, {
39140
+ count: keys.length,
39141
+ totalSize: totalSize,
39142
+ totalSizeMB: (totalSize / 1024 / 1024).toFixed(2),
39143
+ items: items.sort(function (a, b) {
39144
+ return b.size - a.size;
39145
+ })
39146
+ });
39147
+ case 34:
39148
+ _context11.p = 34;
39149
+ _t16 = _context11.v;
39150
+ this.config.onError(_t16);
39151
+ return _context11.a(2, {
39152
+ count: 0,
39153
+ totalSize: 0,
39154
+ totalSizeMB: '0',
39155
+ items: []
39156
+ });
39157
+ }
39158
+ }, _callee11, this, [[25, 31, 32, 33], [7, 13, 14, 15], [3, 18, 19, 20], [1, 34]]);
39159
+ }));
39160
+ function getDetailedStats() {
39161
+ return _getDetailedStats.apply(this, arguments);
39162
+ }
39163
+ return getDetailedStats;
39164
+ }()
39165
+ }]);
39166
+ }();
39167
+ var cacheManager = new CacheManager();
39168
+
38008
39169
  var Rendering2D = /*#__PURE__*/function (_BaseDisposable) {
38009
39170
  function Rendering2D(_canvas) {
38010
39171
  var _this;
@@ -39319,6 +40480,9 @@ var rendering3D = /*#__PURE__*/Object.freeze({
39319
40480
  });
39320
40481
 
39321
40482
  exports.AnimationManager = AnimationManager;
40483
+ exports.CACHE_EXPIRY = CACHE_EXPIRY;
40484
+ exports.CACHE_NAME_PREFIX = CACHE_NAME_PREFIX;
40485
+ exports.CacheManager = CacheManager;
39322
40486
  exports.CameraControlsManager = CameraControlsManager;
39323
40487
  exports.CentralPlant = CentralPlant;
39324
40488
  exports.ComponentDataManager = ComponentDataManager;
@@ -39340,6 +40504,7 @@ exports.SceneOperationsManager = SceneOperationsManager;
39340
40504
  exports.SceneTooltipsManager = SceneTooltipsManager;
39341
40505
  exports.SnapshotManager = SnapshotManager;
39342
40506
  exports.ThreeJSResourceManager = ThreeJSResourceManager;
40507
+ exports.cacheManager = cacheManager;
39343
40508
  exports.createPathfindingRequest = createPathfindingRequest;
39344
40509
  exports.createTransformControls = createTransformControls;
39345
40510
  exports.findObjectByHardcodedUuid = findObjectByHardcodedUuid;