@rive-app/webgl2 2.26.6 → 2.26.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/rive.js CHANGED
@@ -442,7 +442,7 @@ function Oa(a, b) {
442
442
  return Na(c, a, b);
443
443
  }));
444
444
  }
445
- var Pa, Qa, Ua = {510110:(a, b, c, d, e) => {
445
+ var Pa, Qa, Ua = {510302:(a, b, c, d, e) => {
446
446
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
447
447
  return 0;
448
448
  }
@@ -505,9 +505,9 @@ var Pa, Qa, Ua = {510110:(a, b, c, d, e) => {
505
505
  }
506
506
  window.h.Da += 1;
507
507
  return 1;
508
- }, 512288:() => {
508
+ }, 512480:() => {
509
509
  "undefined" !== typeof window.h && (--window.h.Da, 0 === window.h.Da && delete window.h);
510
- }, 512452:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 512556:() => {
510
+ }, 512644:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 512748:() => {
511
511
  try {
512
512
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
513
513
  a.close();
@@ -515,7 +515,7 @@ var Pa, Qa, Ua = {510110:(a, b, c, d, e) => {
515
515
  } catch (c) {
516
516
  return 0;
517
517
  }
518
- }, 512727:(a, b, c, d, e, f) => {
518
+ }, 512919:(a, b, c, d, e, f) => {
519
519
  if ("undefined" === typeof window.h) {
520
520
  return -1;
521
521
  }
@@ -561,7 +561,7 @@ var Pa, Qa, Ua = {510110:(a, b, c, d, e) => {
561
561
  a == window.h.I.Ba && g.Z.connect(g.J.destination);
562
562
  g.lb = f;
563
563
  return window.h.oc(g);
564
- }, 515604:a => window.h.va(a).J.sampleRate, 515677:a => {
564
+ }, 515796:a => window.h.va(a).J.sampleRate, 515869:a => {
565
565
  a = window.h.va(a);
566
566
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
567
567
  }, a.Z.disconnect(), a.Z = void 0);
@@ -569,13 +569,13 @@ var Pa, Qa, Ua = {510110:(a, b, c, d, e) => {
569
569
  a.J.close();
570
570
  a.J = void 0;
571
571
  a.lb = void 0;
572
- }, 516077:a => {
572
+ }, 516269:a => {
573
573
  window.h.yb(a);
574
- }, 516127:a => {
574
+ }, 516319:a => {
575
575
  a = window.h.va(a);
576
576
  a.J.resume();
577
577
  a.state = window.h.ia.tb;
578
- }, 516266:a => {
578
+ }, 516458:a => {
579
579
  a = window.h.va(a);
580
580
  a.J.suspend();
581
581
  a.state = window.h.ia.stopped;
@@ -3493,8 +3493,8 @@ k.dynCall_viijii = (a, b, c, d, e, f, g) => (k.dynCall_viijii = C.dynCall_viijii
3493
3493
  k.dynCall_iiiiij = (a, b, c, d, e, f, g) => (k.dynCall_iiiiij = C.dynCall_iiiiij)(a, b, c, d, e, f, g);
3494
3494
  k.dynCall_iiiiijj = (a, b, c, d, e, f, g, l, p) => (k.dynCall_iiiiijj = C.dynCall_iiiiijj)(a, b, c, d, e, f, g, l, p);
3495
3495
  k.dynCall_iiiiiijj = (a, b, c, d, e, f, g, l, p, m) => (k.dynCall_iiiiiijj = C.dynCall_iiiiiijj)(a, b, c, d, e, f, g, l, p, m);
3496
- k.___start_em_js = 507676;
3497
- k.___stop_em_js = 510110;
3496
+ k.___start_em_js = 507868;
3497
+ k.___stop_em_js = 510302;
3498
3498
  var Zd;
3499
3499
  Ha = function $d() {
3500
3500
  Zd || ae();
@@ -3554,7 +3554,7 @@ ae();
3554
3554
  /* 2 */
3555
3555
  /***/ ((module) => {
3556
3556
 
3557
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.26.6","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3557
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.26.7","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3558
3558
 
3559
3559
  /***/ }),
3560
3560
  /* 3 */
@@ -4104,6 +4104,15 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
4104
4104
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
4105
4105
  }
4106
4106
  };
4107
+ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
4108
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4109
+ if (ar || !(i in from)) {
4110
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
4111
+ ar[i] = from[i];
4112
+ }
4113
+ }
4114
+ return to.concat(ar || Array.prototype.slice.call(from));
4115
+ };
4107
4116
 
4108
4117
 
4109
4118
 
@@ -5497,6 +5506,13 @@ var Rive = /** @class */ (function () {
5497
5506
  useOffscreenRenderer: params.useOffscreenRenderer,
5498
5507
  });
5499
5508
  }
5509
+ Object.defineProperty(Rive.prototype, "viewModelCount", {
5510
+ get: function () {
5511
+ return this.file.viewModelCount();
5512
+ },
5513
+ enumerable: false,
5514
+ configurable: true
5515
+ });
5500
5516
  // Alternative constructor to build a Rive instance from an interface/object
5501
5517
  Rive.new = function (params) {
5502
5518
  console.warn("This function is deprecated: please use `new Rive({})` instead");
@@ -6735,10 +6751,14 @@ var Rive = /** @class */ (function () {
6735
6751
  viewModelInstance.internalIncrementReferenceCount();
6736
6752
  (_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.cleanup();
6737
6753
  this._viewModelInstance = viewModelInstance;
6738
- this.artboard.bindViewModelInstance(viewModelInstance.runtimeInstance);
6739
- this.animator.stateMachines.forEach(function (stateMachine) {
6740
- return stateMachine.bindViewModelInstance(viewModelInstance);
6741
- });
6754
+ if (this.animator.stateMachines.length > 0) {
6755
+ this.animator.stateMachines.forEach(function (stateMachine) {
6756
+ return stateMachine.bindViewModelInstance(viewModelInstance);
6757
+ });
6758
+ }
6759
+ else {
6760
+ this.artboard.bindViewModelInstance(viewModelInstance.runtimeInstance);
6761
+ }
6742
6762
  }
6743
6763
  }
6744
6764
  };
@@ -6872,12 +6892,26 @@ var DataEnum = /** @class */ (function () {
6872
6892
  return DataEnum;
6873
6893
  }());
6874
6894
 
6895
+ var PropertyType;
6896
+ (function (PropertyType) {
6897
+ PropertyType["Number"] = "number";
6898
+ PropertyType["String"] = "string";
6899
+ PropertyType["Boolean"] = "boolean";
6900
+ PropertyType["Color"] = "color";
6901
+ PropertyType["Trigger"] = "trigger";
6902
+ PropertyType["Enum"] = "enum";
6903
+ })(PropertyType || (PropertyType = {}));
6875
6904
  var ViewModelInstance = /** @class */ (function () {
6876
- function ViewModelInstance(runtimeInstance, root) {
6905
+ function ViewModelInstance(runtimeInstance, parent) {
6906
+ this._parents = [];
6907
+ this._children = [];
6908
+ this._viewModelInstances = new Map();
6877
6909
  this._propertiesWithCallbacks = [];
6878
6910
  this._referenceCount = 0;
6879
6911
  this._runtimeInstance = runtimeInstance;
6880
- this._root = root || this;
6912
+ if (parent !== null) {
6913
+ this._parents.push(parent);
6914
+ }
6881
6915
  }
6882
6916
  Object.defineProperty(ViewModelInstance.prototype, "runtimeInstance", {
6883
6917
  get: function () {
@@ -6891,6 +6925,80 @@ var ViewModelInstance = /** @class */ (function () {
6891
6925
  this._propertiesWithCallbacks.forEach(function (property) {
6892
6926
  property.handleCallbacks();
6893
6927
  });
6928
+ this._propertiesWithCallbacks.forEach(function (property) {
6929
+ property.clearChanges();
6930
+ });
6931
+ }
6932
+ this._children.forEach(function (child) { return child.handleCallbacks(); });
6933
+ };
6934
+ ViewModelInstance.prototype.addParent = function (parent) {
6935
+ this._parents.push(parent);
6936
+ if (this._propertiesWithCallbacks.length > 0 || this._children.length > 0) {
6937
+ parent.addToViewModelCallbacks(this);
6938
+ }
6939
+ };
6940
+ ViewModelInstance.prototype.removeParent = function (parent) {
6941
+ var index = this._parents.indexOf(parent);
6942
+ if (index !== -1) {
6943
+ var parent_1 = this._parents[index];
6944
+ parent_1.removeFromViewModelCallbacks(this);
6945
+ this._parents.splice(index, 1);
6946
+ }
6947
+ };
6948
+ /*
6949
+ * method for internal use, it shouldn't be called externally
6950
+ */
6951
+ ViewModelInstance.prototype.addToPropertyCallbacks = function (property) {
6952
+ var _this = this;
6953
+ if (!this._propertiesWithCallbacks.includes(property)) {
6954
+ this._propertiesWithCallbacks.push(property);
6955
+ if (this._propertiesWithCallbacks.length > 0) {
6956
+ this._parents.forEach(function (parent) {
6957
+ parent.addToViewModelCallbacks(_this);
6958
+ });
6959
+ }
6960
+ }
6961
+ };
6962
+ /*
6963
+ * method for internal use, it shouldn't be called externally
6964
+ */
6965
+ ViewModelInstance.prototype.removeFromPropertyCallbacks = function (property) {
6966
+ var _this = this;
6967
+ if (this._propertiesWithCallbacks.includes(property)) {
6968
+ this._propertiesWithCallbacks = this._propertiesWithCallbacks.filter(function (prop) { return prop !== property; });
6969
+ if (this._children.length === 0 &&
6970
+ this._propertiesWithCallbacks.length === 0) {
6971
+ this._parents.forEach(function (parent) {
6972
+ parent.removeFromViewModelCallbacks(_this);
6973
+ });
6974
+ }
6975
+ }
6976
+ };
6977
+ /*
6978
+ * method for internal use, it shouldn't be called externally
6979
+ */
6980
+ ViewModelInstance.prototype.addToViewModelCallbacks = function (instance) {
6981
+ var _this = this;
6982
+ if (!this._children.includes(instance)) {
6983
+ this._children.push(instance);
6984
+ this._parents.forEach(function (parent) {
6985
+ parent.addToViewModelCallbacks(_this);
6986
+ });
6987
+ }
6988
+ };
6989
+ /*
6990
+ * method for internal use, it shouldn't be called externally
6991
+ */
6992
+ ViewModelInstance.prototype.removeFromViewModelCallbacks = function (instance) {
6993
+ var _this = this;
6994
+ if (this._children.includes(instance)) {
6995
+ this._children = this._children.filter(function (child) { return child !== instance; });
6996
+ if (this._children.length === 0 &&
6997
+ this._propertiesWithCallbacks.length === 0) {
6998
+ this._parents.forEach(function (parent) {
6999
+ parent.removeFromViewModelCallbacks(_this);
7000
+ });
7001
+ }
6894
7002
  }
6895
7003
  };
6896
7004
  ViewModelInstance.prototype.clearCallbacks = function () {
@@ -6898,97 +7006,179 @@ var ViewModelInstance = /** @class */ (function () {
6898
7006
  property.clearCallbacks();
6899
7007
  });
6900
7008
  };
7009
+ ViewModelInstance.prototype.propertyFromPath = function (path, type) {
7010
+ var pathSegments = path.split("/");
7011
+ return this.propertyFromPathSegments(pathSegments, 0, type);
7012
+ };
7013
+ ViewModelInstance.prototype.viewModelFromPathSegments = function (pathSegments, index) {
7014
+ var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
7015
+ if (viewModelInstance !== null) {
7016
+ if (index == pathSegments.length - 1) {
7017
+ return viewModelInstance;
7018
+ }
7019
+ else {
7020
+ return viewModelInstance.viewModelFromPathSegments(pathSegments, index++);
7021
+ }
7022
+ }
7023
+ return null;
7024
+ };
7025
+ ViewModelInstance.prototype.propertyFromPathSegments = function (pathSegments, index, type) {
7026
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
7027
+ if (index < pathSegments.length - 1) {
7028
+ var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
7029
+ if (viewModelInstance !== null) {
7030
+ return viewModelInstance.propertyFromPathSegments(pathSegments, index + 1, type);
7031
+ }
7032
+ else {
7033
+ return null;
7034
+ }
7035
+ }
7036
+ var instance = null;
7037
+ switch (type) {
7038
+ case PropertyType.Number:
7039
+ instance = (_b = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.number(pathSegments[index])) !== null && _b !== void 0 ? _b : null;
7040
+ if (instance !== null) {
7041
+ return new ViewModelInstanceNumber(instance, this);
7042
+ }
7043
+ break;
7044
+ case PropertyType.String:
7045
+ instance = (_d = (_c = this._runtimeInstance) === null || _c === void 0 ? void 0 : _c.string(pathSegments[index])) !== null && _d !== void 0 ? _d : null;
7046
+ if (instance !== null) {
7047
+ return new ViewModelInstanceString(instance, this);
7048
+ }
7049
+ break;
7050
+ case PropertyType.Boolean:
7051
+ instance = (_f = (_e = this._runtimeInstance) === null || _e === void 0 ? void 0 : _e.boolean(pathSegments[index])) !== null && _f !== void 0 ? _f : null;
7052
+ if (instance !== null) {
7053
+ return new ViewModelInstanceBoolean(instance, this);
7054
+ }
7055
+ break;
7056
+ case PropertyType.Color:
7057
+ instance = (_h = (_g = this._runtimeInstance) === null || _g === void 0 ? void 0 : _g.color(pathSegments[index])) !== null && _h !== void 0 ? _h : null;
7058
+ if (instance !== null) {
7059
+ return new ViewModelInstanceColor(instance, this);
7060
+ }
7061
+ break;
7062
+ case PropertyType.Trigger:
7063
+ instance = (_k = (_j = this._runtimeInstance) === null || _j === void 0 ? void 0 : _j.trigger(pathSegments[index])) !== null && _k !== void 0 ? _k : null;
7064
+ if (instance !== null) {
7065
+ return new ViewModelInstanceTrigger(instance, this);
7066
+ }
7067
+ break;
7068
+ case PropertyType.Enum:
7069
+ instance = (_m = (_l = this._runtimeInstance) === null || _l === void 0 ? void 0 : _l.enum(pathSegments[index])) !== null && _m !== void 0 ? _m : null;
7070
+ if (instance !== null) {
7071
+ return new ViewModelInstanceEnum(instance, this);
7072
+ }
7073
+ break;
7074
+ }
7075
+ return null;
7076
+ };
7077
+ ViewModelInstance.prototype.internalViewModelInstance = function (name) {
7078
+ var _a;
7079
+ if (this._viewModelInstances.has(name)) {
7080
+ return this._viewModelInstances.get(name);
7081
+ }
7082
+ var viewModelRuntimeInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(name);
7083
+ if (viewModelRuntimeInstance !== null) {
7084
+ var viewModelInstance = new ViewModelInstance(viewModelRuntimeInstance, this);
7085
+ viewModelInstance.internalIncrementReferenceCount();
7086
+ this._viewModelInstances.set(name, viewModelInstance);
7087
+ return viewModelInstance;
7088
+ }
7089
+ return null;
7090
+ };
6901
7091
  /**
6902
7092
  * method to access a property instance of type number belonging
6903
7093
  * to the view model instance or to a nested view model instance
6904
7094
  * @param path - path to the number property
6905
7095
  */
6906
7096
  ViewModelInstance.prototype.number = function (path) {
6907
- var _a;
6908
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.number(path);
6909
- if (instance) {
6910
- return new ViewModelInstanceNumber(instance, this._root);
6911
- }
6912
- return null;
7097
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Number);
7098
+ return viewmodelInstanceValue;
6913
7099
  };
6914
7100
  /**
6915
7101
  * method to access a property instance of type string belonging
6916
7102
  * to the view model instance or to a nested view model instance
6917
- * @param path - path to the number property
7103
+ * @param path - path to the string property
6918
7104
  */
6919
7105
  ViewModelInstance.prototype.string = function (path) {
6920
- var _a;
6921
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.string(path);
6922
- if (instance) {
6923
- return new ViewModelInstanceString(instance, this._root);
6924
- }
6925
- return null;
7106
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.String);
7107
+ return viewmodelInstanceValue;
6926
7108
  };
6927
7109
  /**
6928
7110
  * method to access a property instance of type boolean belonging
6929
7111
  * to the view model instance or to a nested view model instance
6930
- * @param path - path to the number property
7112
+ * @param path - path to the boolean property
6931
7113
  */
6932
7114
  ViewModelInstance.prototype.boolean = function (path) {
6933
- var _a;
6934
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.boolean(path);
6935
- if (instance) {
6936
- return new ViewModelInstanceBoolean(instance, this._root);
6937
- }
6938
- return null;
7115
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Boolean);
7116
+ return viewmodelInstanceValue;
6939
7117
  };
6940
7118
  /**
6941
7119
  * method to access a property instance of type color belonging
6942
7120
  * to the view model instance or to a nested view model instance
6943
- * @param path - path to the number property
7121
+ * @param path - path to the ttrigger property
6944
7122
  */
6945
7123
  ViewModelInstance.prototype.color = function (path) {
6946
- var _a;
6947
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.color(path);
6948
- if (instance) {
6949
- return new ViewModelInstanceColor(instance, this._root);
6950
- }
6951
- return null;
7124
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Color);
7125
+ return viewmodelInstanceValue;
6952
7126
  };
6953
7127
  /**
6954
7128
  * method to access a property instance of type trigger belonging
6955
7129
  * to the view model instance or to a nested view model instance
6956
- * @param path - path to the number property
7130
+ * @param path - path to the trigger property
6957
7131
  */
6958
7132
  ViewModelInstance.prototype.trigger = function (path) {
6959
- var _a;
6960
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.trigger(path);
6961
- if (instance) {
6962
- return new ViewModelInstanceTrigger(instance, this._root);
6963
- }
6964
- return null;
7133
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Trigger);
7134
+ return viewmodelInstanceValue;
6965
7135
  };
6966
7136
  /**
6967
7137
  * method to access a property instance of type enum belonging
6968
7138
  * to the view model instance or to a nested view model instance
6969
- * @param path - path to the number property
7139
+ * @param path - path to the enum property
6970
7140
  */
6971
7141
  ViewModelInstance.prototype.enum = function (path) {
6972
- var _a;
6973
- var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.enum(path);
6974
- if (instance) {
6975
- return new ViewModelInstanceEnum(instance, this._root);
6976
- }
6977
- return null;
7142
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Enum);
7143
+ return viewmodelInstanceValue;
6978
7144
  };
6979
7145
  /**
6980
7146
  * method to access a view model property instance belonging
6981
7147
  * to the view model instance or to a nested view model instance
6982
- * @param path - path to the number property
7148
+ * @param path - path to the view model property
6983
7149
  */
6984
7150
  ViewModelInstance.prototype.viewModel = function (path) {
6985
- var _a;
6986
- var viewModelInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(path);
6987
- if (viewModelInstance) {
6988
- return new ViewModelInstance(viewModelInstance, this._root);
7151
+ var pathSegments = path.split("/");
7152
+ var parentViewModelInstance = pathSegments.length > 1
7153
+ ? this.viewModelFromPathSegments(pathSegments.slice(0, pathSegments.length - 1), 0)
7154
+ : this;
7155
+ if (parentViewModelInstance != null) {
7156
+ return parentViewModelInstance.internalViewModelInstance(pathSegments[pathSegments.length - 1]);
6989
7157
  }
6990
7158
  return null;
6991
7159
  };
7160
+ ViewModelInstance.prototype.internalReplaceViewModel = function (name, value) {
7161
+ var _a;
7162
+ if (value.runtimeInstance !== null) {
7163
+ var result = ((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.replaceViewModel(name, value.runtimeInstance)) ||
7164
+ false;
7165
+ if (result) {
7166
+ value.internalIncrementReferenceCount();
7167
+ var oldInstance_1 = this.internalViewModelInstance(name);
7168
+ if (oldInstance_1 !== null) {
7169
+ oldInstance_1.removeParent(this);
7170
+ if (this._children.includes(oldInstance_1)) {
7171
+ this._children = this._children.filter(function (child) { return child !== oldInstance_1; });
7172
+ }
7173
+ oldInstance_1.cleanup();
7174
+ }
7175
+ this._viewModelInstances.set(name, value);
7176
+ value.addParent(this);
7177
+ }
7178
+ return result;
7179
+ }
7180
+ return false;
7181
+ };
6992
7182
  /**
6993
7183
  * method to replace a view model property with another view model value
6994
7184
  * @param path - path to the view model property
@@ -6996,27 +7186,11 @@ var ViewModelInstance = /** @class */ (function () {
6996
7186
  */
6997
7187
  ViewModelInstance.prototype.replaceViewModel = function (path, value) {
6998
7188
  var _a;
6999
- if (value.runtimeInstance !== null) {
7000
- return (((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.replaceViewModel(path, value.runtimeInstance)) ||
7001
- false);
7002
- }
7003
- return false;
7004
- };
7005
- /*
7006
- * method for internal use, it shouldn't be called externally
7007
- */
7008
- ViewModelInstance.prototype.addToCallbacks = function (property) {
7009
- if (!this._propertiesWithCallbacks.includes(property)) {
7010
- this._propertiesWithCallbacks.push(property);
7011
- }
7012
- };
7013
- /*
7014
- * method for internal use, it shouldn't be called externally
7015
- */
7016
- ViewModelInstance.prototype.removeFromCallbacks = function (property) {
7017
- if (this._propertiesWithCallbacks.includes(property)) {
7018
- this._propertiesWithCallbacks = this._propertiesWithCallbacks.filter(function (prop) { return prop !== property; });
7019
- }
7189
+ var pathSegments = path.split("/");
7190
+ var viewModelInstance = pathSegments.length > 1
7191
+ ? this.viewModelFromPathSegments(pathSegments.slice(0, pathSegments.length - 1), 0)
7192
+ : this;
7193
+ return ((_a = viewModelInstance === null || viewModelInstance === void 0 ? void 0 : viewModelInstance.internalReplaceViewModel(pathSegments[pathSegments.length - 1], value)) !== null && _a !== void 0 ? _a : false);
7020
7194
  };
7021
7195
  /*
7022
7196
  * method to add one to the reference counter of the instance.
@@ -7048,21 +7222,36 @@ var ViewModelInstance = /** @class */ (function () {
7048
7222
  this._referenceCount++;
7049
7223
  };
7050
7224
  ViewModelInstance.prototype.cleanup = function () {
7225
+ var _this = this;
7051
7226
  this._referenceCount--;
7052
7227
  if (this._referenceCount <= 0) {
7053
7228
  this._runtimeInstance = null;
7054
7229
  this.clearCallbacks();
7055
7230
  this._propertiesWithCallbacks = [];
7231
+ this._viewModelInstances.forEach(function (value) {
7232
+ value.cleanup();
7233
+ });
7234
+ this._viewModelInstances.clear();
7235
+ var children = __spreadArray([], this._children, true);
7236
+ this._children.length = 0;
7237
+ var parents = __spreadArray([], this._parents, true);
7238
+ this._parents.length = 0;
7239
+ children.forEach(function (child) {
7240
+ child.removeParent(_this);
7241
+ });
7242
+ parents.forEach(function (parent) {
7243
+ parent.removeFromViewModelCallbacks(_this);
7244
+ });
7056
7245
  }
7057
7246
  };
7058
7247
  return ViewModelInstance;
7059
7248
  }());
7060
7249
 
7061
7250
  var ViewModelInstanceValue = /** @class */ (function () {
7062
- function ViewModelInstanceValue(instance, root) {
7251
+ function ViewModelInstanceValue(instance, parent) {
7063
7252
  this.callbacks = [];
7064
7253
  this._viewModelInstanceValue = instance;
7065
- this._rootViewModel = root;
7254
+ this._parentViewModel = parent;
7066
7255
  }
7067
7256
  ViewModelInstanceValue.prototype.on = function (callback) {
7068
7257
  // Since we don't clean the changed flag for properties that don't have listeners,
@@ -7072,7 +7261,7 @@ var ViewModelInstanceValue = /** @class */ (function () {
7072
7261
  }
7073
7262
  if (!this.callbacks.includes(callback)) {
7074
7263
  this.callbacks.push(callback);
7075
- this._rootViewModel.addToCallbacks(this);
7264
+ this._parentViewModel.addToPropertyCallbacks(this);
7076
7265
  }
7077
7266
  };
7078
7267
  ViewModelInstanceValue.prototype.off = function (callback) {
@@ -7083,19 +7272,21 @@ var ViewModelInstanceValue = /** @class */ (function () {
7083
7272
  this.callbacks = this.callbacks.filter(function (cb) { return cb !== callback; });
7084
7273
  }
7085
7274
  if (this.callbacks.length === 0) {
7086
- this._rootViewModel.removeFromCallbacks(this);
7275
+ this._parentViewModel.removeFromPropertyCallbacks(this);
7087
7276
  }
7088
7277
  };
7089
7278
  ViewModelInstanceValue.prototype.internalHandleCallback = function (callback) { };
7090
7279
  ViewModelInstanceValue.prototype.handleCallbacks = function () {
7091
7280
  var _this = this;
7092
7281
  if (this._viewModelInstanceValue.hasChanged) {
7093
- this._viewModelInstanceValue.clearChanges();
7094
7282
  this.callbacks.forEach(function (callback) {
7095
7283
  _this.internalHandleCallback(callback);
7096
7284
  });
7097
7285
  }
7098
7286
  };
7287
+ ViewModelInstanceValue.prototype.clearChanges = function () {
7288
+ this._viewModelInstanceValue.clearChanges();
7289
+ };
7099
7290
  ViewModelInstanceValue.prototype.clearCallbacks = function () {
7100
7291
  this.callbacks.length = 0;
7101
7292
  };
@@ -7111,8 +7302,8 @@ var ViewModelInstanceValue = /** @class */ (function () {
7111
7302
 
7112
7303
  var ViewModelInstanceString = /** @class */ (function (_super) {
7113
7304
  __extends(ViewModelInstanceString, _super);
7114
- function ViewModelInstanceString(instance, root) {
7115
- return _super.call(this, instance, root) || this;
7305
+ function ViewModelInstanceString(instance, parent) {
7306
+ return _super.call(this, instance, parent) || this;
7116
7307
  }
7117
7308
  Object.defineProperty(ViewModelInstanceString.prototype, "value", {
7118
7309
  get: function () {
@@ -7132,8 +7323,8 @@ var ViewModelInstanceString = /** @class */ (function (_super) {
7132
7323
 
7133
7324
  var ViewModelInstanceNumber = /** @class */ (function (_super) {
7134
7325
  __extends(ViewModelInstanceNumber, _super);
7135
- function ViewModelInstanceNumber(instance, root) {
7136
- return _super.call(this, instance, root) || this;
7326
+ function ViewModelInstanceNumber(instance, parent) {
7327
+ return _super.call(this, instance, parent) || this;
7137
7328
  }
7138
7329
  Object.defineProperty(ViewModelInstanceNumber.prototype, "value", {
7139
7330
  get: function () {
@@ -7153,8 +7344,8 @@ var ViewModelInstanceNumber = /** @class */ (function (_super) {
7153
7344
 
7154
7345
  var ViewModelInstanceBoolean = /** @class */ (function (_super) {
7155
7346
  __extends(ViewModelInstanceBoolean, _super);
7156
- function ViewModelInstanceBoolean(instance, root) {
7157
- return _super.call(this, instance, root) || this;
7347
+ function ViewModelInstanceBoolean(instance, parent) {
7348
+ return _super.call(this, instance, parent) || this;
7158
7349
  }
7159
7350
  Object.defineProperty(ViewModelInstanceBoolean.prototype, "value", {
7160
7351
  get: function () {
@@ -7174,8 +7365,8 @@ var ViewModelInstanceBoolean = /** @class */ (function (_super) {
7174
7365
 
7175
7366
  var ViewModelInstanceTrigger = /** @class */ (function (_super) {
7176
7367
  __extends(ViewModelInstanceTrigger, _super);
7177
- function ViewModelInstanceTrigger(instance, root) {
7178
- return _super.call(this, instance, root) || this;
7368
+ function ViewModelInstanceTrigger(instance, parent) {
7369
+ return _super.call(this, instance, parent) || this;
7179
7370
  }
7180
7371
  ViewModelInstanceTrigger.prototype.trigger = function () {
7181
7372
  return this._viewModelInstanceValue.trigger();
@@ -7188,8 +7379,8 @@ var ViewModelInstanceTrigger = /** @class */ (function (_super) {
7188
7379
 
7189
7380
  var ViewModelInstanceEnum = /** @class */ (function (_super) {
7190
7381
  __extends(ViewModelInstanceEnum, _super);
7191
- function ViewModelInstanceEnum(instance, root) {
7192
- return _super.call(this, instance, root) || this;
7382
+ function ViewModelInstanceEnum(instance, parent) {
7383
+ return _super.call(this, instance, parent) || this;
7193
7384
  }
7194
7385
  Object.defineProperty(ViewModelInstanceEnum.prototype, "value", {
7195
7386
  get: function () {
@@ -7227,8 +7418,8 @@ var ViewModelInstanceEnum = /** @class */ (function (_super) {
7227
7418
 
7228
7419
  var ViewModelInstanceColor = /** @class */ (function (_super) {
7229
7420
  __extends(ViewModelInstanceColor, _super);
7230
- function ViewModelInstanceColor(instance, root) {
7231
- return _super.call(this, instance, root) || this;
7421
+ function ViewModelInstanceColor(instance, parent) {
7422
+ return _super.call(this, instance, parent) || this;
7232
7423
  }
7233
7424
  Object.defineProperty(ViewModelInstanceColor.prototype, "value", {
7234
7425
  get: function () {