πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

x-view-model

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

x-view-model - npm Package Compare versions

Comparing version

to
3.0.8

2

lib/index.esm.js

@@ -1214,3 +1214,3 @@ import { useState, useCallback, useMemo, useEffect, useRef } from 'react';

var state = useInterfaceHandle(keys, vm.context);
return [state, vm.context.send, vm.ref];
return [state, vm.context.send.bind(vm.context), vm.ref];
};

@@ -1217,0 +1217,0 @@ var useComputedViewModel = function (vm, selector, keys) {

@@ -15,3 +15,3 @@ import{useState as t,useCallback as e,useMemo as r,useEffect as n,useRef as o}from"react";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},s(t,e)};function i(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var a=function(){return a=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},a.apply(this,arguments)};function c(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{c(n.next(t))}catch(t){s(t)}}function a(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}c((n=n.apply(t,e||[])).next())}))}function h(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}const l="insert",f="update",u="delete",p="reverse",y="shuffle",d=Symbol.for("object-observer-meta-key-0"),b={async:1},v=t=>{if(!t||"object"!=typeof t)return null;const e={},r=[];for(const[n,o]of Object.entries(t))if("path"===n){if("string"!=typeof o||""===o)throw new Error('"path" option, if/when provided, MUST be a non-empty string');e[n]=o}else if("pathsOf"===n){if(t.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if("string"!=typeof o)throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');e[n]=t.pathsOf.split(".").filter(Boolean)}else if("pathsFrom"===n){if(t.path||t.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if("string"!=typeof o||""===o)throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');e[n]=o}else r.push(n);if(r.length)throw new Error(`'${r.join(", ")}' is/are not a valid observer option/s`);return e},w=(t,e)=>{const r={};r[d]=e;for(const n in t)r[n]=M(t[n],n,e);return r},g=(t,e)=>{let r=t.length;const n=new Array(r);n[d]=e;for(let o=0;o<r;o++)n[o]=M(t[o],o,e);return n},m=(t,e)=>(t[d]=e,t),_=(t,e)=>{if(null===t)return e;let r=e;if(t.path){const n=t.path;r=e.filter((t=>t.path.join(".")===n))}else if(t.pathsOf){const n=t.pathsOf,o=n.join(".");r=e.filter((t=>(t.path.length===n.length+1||t.path.length===n.length&&(t.type===p||t.type===y))&&t.path.join(".").startsWith(o)))}else if(t.pathsFrom){const n=t.pathsFrom;r=e.filter((t=>t.path.join(".").startsWith(n)))}return r},j=(t,e)=>{try{t(e)}catch(r){console.error(`failed to notify listener ${t} with ${e}`,r)}},O=function(){const t=this.batches;this.batches=[];for(const[e,r]of t)j(e,r)},x=(t,e)=>{let r,n,o,s,i,a,c=t;const h=e.length;do{for(r=c.options.async,n=c.observers,a=n.length;a--;)if([o,s]=n[a],i=_(s,e),i.length)if(r){let t;0===c.batches.length&&queueMicrotask(O.bind(c));for(const e of c.batches)if(e[0]===o){t=e;break}t||(t=[o,[]],c.batches.push(t)),Array.prototype.push.apply(t[1],i)}else j(o,i);const t=c.parent;if(t){for(let t=0;t<h;t++){const r=e[t];e[t]=new P(r.type,[c.ownKey,...r.path],r.value,r.oldValue,r.object)}c=t}else c=null}while(c)},M=(t,e,r)=>"object"!=typeof t||null===t?t:Array.isArray(t)?new F({target:t,ownKey:e,parent:r}).proxy:ArrayBuffer.isView(t)?new R({target:t,ownKey:e,parent:r}).proxy:t instanceof Date?t:new N({target:t,ownKey:e,parent:r}).proxy,A=function(){const t=this[d],e=t.target;let r,n,o;for(e.reverse(),r=0,n=e.length;r<n;r++)if(o=e[r],o&&"object"==typeof o){const t=o[d];t&&(t.ownKey=r)}const s=[new P(p,[],void 0,void 0,this)];return x(t,s),this},E=function(t){const e=this[d],r=e.target;let n,o,s;for(r.sort(t),n=0,o=r.length;n<o;n++)if(s=r[n],s&&"object"==typeof s){const t=s[d];t&&(t.ownKey=n)}const i=[new P(y,[],void 0,void 0,this)];return x(e,i),this},S=function(t,e,r){const n=this[d],o=n.target,s=[],i=o.length,a=o.slice(0);if(e=void 0===e?0:e<0?Math.max(i+e,0):Math.min(e,i),r=void 0===r?i:r<0?Math.max(i+r,0):Math.min(r,i),e<i&&r>e){let i;o.fill(t,e,r);for(let t,c,h=e;h<r;h++)t=o[h],o[h]=M(t,h,n),h in a?(c=a[h],c&&"object"==typeof c&&(i=c[d],i&&(c=i.detach())),s.push(new P(f,[h],o[h],c,this))):s.push(new P(l,[h],o[h],void 0,this));x(n,s)}return this},H=function(t,e,r){const n=this[d],o=n.target,s=o.length;t=t<0?Math.max(s+t,0):t,e=void 0===e?0:e<0?Math.max(s+e,0):Math.min(e,s),r=void 0===r?s:r<0?Math.max(s+r,0):Math.min(r,s);const i=Math.min(r-e,s-t);if(t<s&&t!==e&&i>0){const s=o.slice(0),a=[];o.copyWithin(t,e,r);for(let e,r,c,h=t;h<t+i;h++)e=o[h],e&&"object"==typeof e&&(e=M(e,h,n),o[h]=e),r=s[h],r&&"object"==typeof r&&(c=r[d],c&&(r=c.detach())),"object"!=typeof e&&e===r||a.push(new P(f,[h],e,r,this));x(n,a)}return this},K={pop:function(){const t=this[d],e=t.target,r=e.length-1;let n=e.pop();if(n&&"object"==typeof n){const t=n[d];t&&(n=t.detach())}const o=[new P(u,[r],void 0,n,this)];return x(t,o),n},push:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=M(arguments[e],o+e,t);const s=Reflect.apply(e.push,e,n),i=[];for(let t=o,r=e.length;t<r;t++)i[t-o]=new P(l,[t],e[t],void 0,this);return x(t,i),s},shift:function(){const t=this[d],e=t.target;let r,n,o,s,i;for(r=e.shift(),r&&"object"==typeof r&&(i=r[d],i&&(r=i.detach())),n=0,o=e.length;n<o;n++)s=e[n],s&&"object"==typeof s&&(i=s[d],i&&(i.ownKey=n));const a=[new P(u,[0],void 0,r,this)];return x(t,a),r},unshift:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r);for(let e=0;e<r;e++)n[e]=M(arguments[e],e,t);const o=Reflect.apply(e.unshift,e,n);for(let t,r=0,n=e.length;r<n;r++)if(t=e[r],t&&"object"==typeof t){const e=t[d];e&&(e.ownKey=r)}const s=n.length,i=new Array(s);for(let t=0;t<s;t++)i[t]=new P(l,[t],e[t],void 0,this);return x(t,i),o},reverse:A,sort:E,fill:S,copyWithin:H,splice:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=M(arguments[e],e,t);const s=0===r?0:n[0]<0?o+n[0]:n[0],i=r<2?o-s:n[1],a=Math.max(r-2,0),c=Reflect.apply(e.splice,e,n),h=e.length;let p,y,b,v;for(let t,r=0;r<h;r++)t=e[r],t&&"object"==typeof t&&(p=t[d],p&&(p.ownKey=r));for(y=0,b=c.length;y<b;y++)v=c[y],v&&"object"==typeof v&&(p=v[d],p&&(c[y]=p.detach()));const w=[];let g;for(g=0;g<i;g++)g<a?w.push(new P(f,[s+g],e[s+g],c[g],this)):w.push(new P(u,[s+g],void 0,c[g],this));for(;g<a;g++)w.push(new P(l,[s+g],e[s+g],void 0,this));return x(t,w),c}},k={reverse:A,sort:E,fill:S,copyWithin:H,set:function(t,e){const r=this[d],n=r.target,o=t.length,s=n.slice(0);e=e||0,n.set(t,e);const i=new Array(o);for(let t=e;t<o+e;t++)i[t-e]=new P(f,[t],n[t],s[t],this);x(r,i)}};class P{constructor(t,e,r,n,o){this.type=t,this.path=e,this.value=r,this.oldValue=n,this.object=o}}class T{constructor(t,e){const{target:r,parent:n,ownKey:o}=t;n&&void 0!==o?(this.parent=n,this.ownKey=o):(this.parent=null,this.ownKey=null);const s=e(r,this);this.observers=[],this.revocable=Proxy.revocable(s,this),this.proxy=this.revocable.proxy,this.target=s,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if("object"!=typeof t)throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter((t=>!(t in b)));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}return{}}detach(){return this.parent=null,this.target}set(t,e,r){let n=t[e];if(r!==n){const o=M(r,e,this);if(t[e]=o,n&&"object"==typeof n){const t=n[d];t&&(n=t.detach())}const s=void 0===n?[new P(l,[e],o,void 0,this.proxy)]:[new P(f,[e],o,n,this.proxy)];x(this,s)}return!0}deleteProperty(t,e){let r=t[e];if(delete t[e],r&&"object"==typeof r){const t=r[d];t&&(r=t.detach())}const n=[new P(u,[e],void 0,r,this.proxy)];return x(this,n),!0}}class N extends T{constructor(t){super(t,w)}}class F extends T{constructor(t){super(t,g)}get(t,e){return K[e]||t[e]}}class R extends T{constructor(t){super(t,m)}get(t,e){return k[e]||t[e]}}const $=Object.freeze({from:(t,e)=>{if(t&&"object"==typeof t){if(t[d])return t;if(Array.isArray(t))return new F({target:t,ownKey:null,parent:null,options:e}).proxy;if(ArrayBuffer.isView(t))return new R({target:t,ownKey:null,parent:null,options:e}).proxy;if(t instanceof Date)throw new Error(`${t} found to be one of a non-observable types`);return new N({target:t,ownKey:null,parent:null,options:e}).proxy}throw new Error("observable MAY ONLY be created from a non-null object")},isObservable:t=>!(!t||!t[d]),observe:(t,e,r)=>{if(!$.isObservable(t))throw new Error("invalid observable parameter");if("function"!=typeof e)throw new Error(`observer MUST be a function, got '${e}'`);const n=t[d].observers;n.some((t=>t[0]===e))?console.warn("observer may be bound to an observable only once; will NOT rebind"):n.push([e,v(r)])},unobserve:(t,...e)=>{if(!$.isObservable(t))throw new Error("invalid observable parameter");const r=t[d].observers;let n=r.length;if(n)if(e.length)for(;n;){e.indexOf(r[--n][0])>=0&&r.splice(n,1)}else r.splice(0)}});var Y=function(){var t=this;this.on=function(e,r){return t.handlers[e]=t.handlers[e]||[],t.handlers[e].push(r),t},this.off=function(e,r){var n=t.handlers[e];if(n)for(var o=0;o<n.length;o++)n[o]===r&&n.splice(o,1);return t},this.callEmitFromMT=function(){this.func.apply(null,this.args?this.args:[])},this.emit=function(e,r){if(t.handlers[e])for(var n=0;n<t.handlers[e].length;n++)try{queueMicrotask(t.callEmitFromMT.bind({func:t.handlers[e][n],args:r}))}catch(t){console.log(t)}return t},this.clear=function(){t.handlers={}},this.handlers={}},z=function(t){function e(e){var r=t.call(this)||this;return Object.keys(e.property).forEach((function(t){r.on(t,(function(r){try{e.property[t].apply(e.state,[r])}catch(t){console.log(t)}}))})),r}return i(e,t),e}(Y),D=function(t){function e(e,r){var n,o,s=this;return(s=t.call(this)||this).middlewares=[],s._sendHistory=[],s.watch=function(t){return c(s,void 0,void 0,(function(){var e,r,n=this;return h(this,(function(o){switch(o.label){case 0:return e=performance.now(),[4,this.executeMiddlewares(t,(function(){for(var e,r=function(t){var r=t.path.filter((function(t){return"number"!=typeof t}));if(null===(e=n._options)||void 0===e?void 0:e.deep){var o="";r.forEach((function(e){o+=e+".",n.emit(o.substring(0,o.length-1),[t.object])}))}else{var s=r.join(".");n.emit(s,[t.object])}},o=0,s=t;o<s.length;o++){r(s[o])}}))];case 1:return o.sent(),"development"===process.env.NODE_ENV&&(r=performance.now()-e)>33.34&&console.warn("[x-view-model] Slow state update detected (".concat(r.toFixed(2),"ms)"),t),[2]}}))}))},s._property=e,s._options=r,s._reference=0,s._observable=$.from(a({},s._property),{async:!0}),s._started=!1,s.services=new z(s),s._historyHandler=(null===(n=null==r?void 0:r.history)||void 0===n?void 0:n.handler)||function(){},s._historyMaxSize=(null===(o=null==r?void 0:r.history)||void 0===o?void 0:o.maxSize)||100,s.middlewares=(null==r?void 0:r.middlewares)||[],s}return i(e,t),e.prototype.use=function(t){return this.middlewares.push(t),this},e.prototype.executeMiddlewares=function(t,e){return c(this,void 0,void 0,(function(){var r=this;return h(this,(function(n){switch(n.label){case 0:return 0===this.middlewares.length?(e(),[2]):[4,this.middlewares.reduceRight((function(e,n){return function(){return n(t,e,r.state)}}),e)()];case 1:return n.sent(),[2]}}))}))},Object.defineProperty(e.prototype,"state",{get:function(){return this._observable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"property",{get:function(){return this._property},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"reference",{get:function(){return this._reference},set:function(t){this._reference=t,this._reference>0?this.start():this.stop()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._options&&this._options.name?this._options.name:"unnamed"},enumerable:!1,configurable:!0}),e.prototype.increaseReference=function(){this.reference++},e.prototype.decreaseReference=function(){this.reference--},e.prototype.start=function(){if(!this._started)return $.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.stop=function(){if(this._started)return $.unobserve(this._observable),this._observable=$.from(a({},this._property)),this._started=!1,this},e.prototype.pause=function(){if(this._started)return $.unobserve(this._observable),this},e.prototype.restart=function(){return $.unobserve(this._observable),this._observable=$.from(a({},this._property)),$.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.snapshot=function(){this.pause();var t=JSON.stringify(this._observable);return this.start(),t},e.prototype.rebase=function(t){var e="string"==typeof t?JSON.parse(t):t;return this._property=a(a({},this._property),e),this},e.prototype.restore=function(t){this.pause();var e="string"==typeof t?JSON.parse(t):t;return this._observable=$.from(a(a({},this._property),e)),this.start(),this},e.prototype.addHistory=function(t){return c(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return this._historyHandler?[4,Promise.resolve(this._historyHandler(t,this.state))]:[3,2];case 1:e.sent(),e.label=2;case 2:return this._sendHistory.push(t),this._sendHistory.length>this._historyMaxSize&&(this._sendHistory=this._sendHistory.slice(-this._historyMaxSize)),[2]}}))}))},e.prototype.send=function(t,e,r){return void 0===r&&(r=!1),c(this,void 0,void 0,(function(){var n,o,s;return h(this,(function(i){switch(i.label){case 0:if(n={name:t,payload:e,timestamp:Date.now()},!r)return[3,7];i.label=1;case 1:return i.trys.push([1,4,,6]),[4,this.property[t].apply(this.state,[e])];case 2:return o=i.sent(),n.result=o,[4,this.addHistory(n)];case 3:return i.sent(),[2,o];case 4:return s=i.sent(),n.error=s,[4,this.addHistory(n)];case 5:throw i.sent(),s;case 6:return[3,9];case 7:return this.services.emit(t,[e]),[4,this.addHistory(n)];case 8:return i.sent(),[2,void 0];case 9:return[2]}}))}))},e.prototype.getSendHistory=function(){return this._sendHistory},e.prototype.clearSendHistory=function(){this._sendHistory=[]},e}(Y),U=function(t,e,r){return{context:new D(t,e),ref:r}},V=function(s,i){var a,c,h;o("".concat(Date.now(),"-").concat(Math.random())).current,o((null===(h=null===(c=null===(a=(new Error).stack)||void 0===a?void 0:a.split("\n")[2])||void 0===c?void 0:c.trim())||void 0===h?void 0:h.split(" ")[1])||"Unknown").current;var l=function(o,s){var i=t(0);i[0];var a=i[1],c=e((function(t){a((function(t){return t+1}))}),[]);return r((function(){s.increaseReference(),Array.isArray(o)?o.forEach((function(t){s.on(t,c)})):s.on(o,c)}),[s]),n((function(){return function(){s.decreaseReference(),Array.isArray(o)?o.forEach((function(t){s.off(t,c)})):s.off(o,c)}}),[s]),s.state}(i,s.context);return[l,s.context.send,s.ref]},W=function(t,e,n){var o=V(t,n),s=o[0],i=o[1],a=o[2];return[r((function(){return e(s)}),[s,e]),i,a]},B=function(t,e){var r=V(t,e);return[r[0],r[1],r[2]]};export{D as PropertyHandler,U as registViewModel,W as useComputedViewModel,B as useMemoizedViewModel,V as useViewModel};
***************************************************************************** */var s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},s(t,e)};function i(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var a=function(){return a=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},a.apply(this,arguments)};function c(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{c(n.next(t))}catch(t){s(t)}}function a(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}c((n=n.apply(t,e||[])).next())}))}function h(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}const l="insert",f="update",u="delete",p="reverse",y="shuffle",d=Symbol.for("object-observer-meta-key-0"),b={async:1},v=t=>{if(!t||"object"!=typeof t)return null;const e={},r=[];for(const[n,o]of Object.entries(t))if("path"===n){if("string"!=typeof o||""===o)throw new Error('"path" option, if/when provided, MUST be a non-empty string');e[n]=o}else if("pathsOf"===n){if(t.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if("string"!=typeof o)throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');e[n]=t.pathsOf.split(".").filter(Boolean)}else if("pathsFrom"===n){if(t.path||t.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if("string"!=typeof o||""===o)throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');e[n]=o}else r.push(n);if(r.length)throw new Error(`'${r.join(", ")}' is/are not a valid observer option/s`);return e},w=(t,e)=>{const r={};r[d]=e;for(const n in t)r[n]=M(t[n],n,e);return r},g=(t,e)=>{let r=t.length;const n=new Array(r);n[d]=e;for(let o=0;o<r;o++)n[o]=M(t[o],o,e);return n},m=(t,e)=>(t[d]=e,t),_=(t,e)=>{if(null===t)return e;let r=e;if(t.path){const n=t.path;r=e.filter((t=>t.path.join(".")===n))}else if(t.pathsOf){const n=t.pathsOf,o=n.join(".");r=e.filter((t=>(t.path.length===n.length+1||t.path.length===n.length&&(t.type===p||t.type===y))&&t.path.join(".").startsWith(o)))}else if(t.pathsFrom){const n=t.pathsFrom;r=e.filter((t=>t.path.join(".").startsWith(n)))}return r},j=(t,e)=>{try{t(e)}catch(r){console.error(`failed to notify listener ${t} with ${e}`,r)}},x=function(){const t=this.batches;this.batches=[];for(const[e,r]of t)j(e,r)},O=(t,e)=>{let r,n,o,s,i,a,c=t;const h=e.length;do{for(r=c.options.async,n=c.observers,a=n.length;a--;)if([o,s]=n[a],i=_(s,e),i.length)if(r){let t;0===c.batches.length&&queueMicrotask(x.bind(c));for(const e of c.batches)if(e[0]===o){t=e;break}t||(t=[o,[]],c.batches.push(t)),Array.prototype.push.apply(t[1],i)}else j(o,i);const t=c.parent;if(t){for(let t=0;t<h;t++){const r=e[t];e[t]=new P(r.type,[c.ownKey,...r.path],r.value,r.oldValue,r.object)}c=t}else c=null}while(c)},M=(t,e,r)=>"object"!=typeof t||null===t?t:Array.isArray(t)?new F({target:t,ownKey:e,parent:r}).proxy:ArrayBuffer.isView(t)?new R({target:t,ownKey:e,parent:r}).proxy:t instanceof Date?t:new N({target:t,ownKey:e,parent:r}).proxy,A=function(){const t=this[d],e=t.target;let r,n,o;for(e.reverse(),r=0,n=e.length;r<n;r++)if(o=e[r],o&&"object"==typeof o){const t=o[d];t&&(t.ownKey=r)}const s=[new P(p,[],void 0,void 0,this)];return O(t,s),this},E=function(t){const e=this[d],r=e.target;let n,o,s;for(r.sort(t),n=0,o=r.length;n<o;n++)if(s=r[n],s&&"object"==typeof s){const t=s[d];t&&(t.ownKey=n)}const i=[new P(y,[],void 0,void 0,this)];return O(e,i),this},S=function(t,e,r){const n=this[d],o=n.target,s=[],i=o.length,a=o.slice(0);if(e=void 0===e?0:e<0?Math.max(i+e,0):Math.min(e,i),r=void 0===r?i:r<0?Math.max(i+r,0):Math.min(r,i),e<i&&r>e){let i;o.fill(t,e,r);for(let t,c,h=e;h<r;h++)t=o[h],o[h]=M(t,h,n),h in a?(c=a[h],c&&"object"==typeof c&&(i=c[d],i&&(c=i.detach())),s.push(new P(f,[h],o[h],c,this))):s.push(new P(l,[h],o[h],void 0,this));O(n,s)}return this},H=function(t,e,r){const n=this[d],o=n.target,s=o.length;t=t<0?Math.max(s+t,0):t,e=void 0===e?0:e<0?Math.max(s+e,0):Math.min(e,s),r=void 0===r?s:r<0?Math.max(s+r,0):Math.min(r,s);const i=Math.min(r-e,s-t);if(t<s&&t!==e&&i>0){const s=o.slice(0),a=[];o.copyWithin(t,e,r);for(let e,r,c,h=t;h<t+i;h++)e=o[h],e&&"object"==typeof e&&(e=M(e,h,n),o[h]=e),r=s[h],r&&"object"==typeof r&&(c=r[d],c&&(r=c.detach())),"object"!=typeof e&&e===r||a.push(new P(f,[h],e,r,this));O(n,a)}return this},K={pop:function(){const t=this[d],e=t.target,r=e.length-1;let n=e.pop();if(n&&"object"==typeof n){const t=n[d];t&&(n=t.detach())}const o=[new P(u,[r],void 0,n,this)];return O(t,o),n},push:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=M(arguments[e],o+e,t);const s=Reflect.apply(e.push,e,n),i=[];for(let t=o,r=e.length;t<r;t++)i[t-o]=new P(l,[t],e[t],void 0,this);return O(t,i),s},shift:function(){const t=this[d],e=t.target;let r,n,o,s,i;for(r=e.shift(),r&&"object"==typeof r&&(i=r[d],i&&(r=i.detach())),n=0,o=e.length;n<o;n++)s=e[n],s&&"object"==typeof s&&(i=s[d],i&&(i.ownKey=n));const a=[new P(u,[0],void 0,r,this)];return O(t,a),r},unshift:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r);for(let e=0;e<r;e++)n[e]=M(arguments[e],e,t);const o=Reflect.apply(e.unshift,e,n);for(let t,r=0,n=e.length;r<n;r++)if(t=e[r],t&&"object"==typeof t){const e=t[d];e&&(e.ownKey=r)}const s=n.length,i=new Array(s);for(let t=0;t<s;t++)i[t]=new P(l,[t],e[t],void 0,this);return O(t,i),o},reverse:A,sort:E,fill:S,copyWithin:H,splice:function(){const t=this[d],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=M(arguments[e],e,t);const s=0===r?0:n[0]<0?o+n[0]:n[0],i=r<2?o-s:n[1],a=Math.max(r-2,0),c=Reflect.apply(e.splice,e,n),h=e.length;let p,y,b,v;for(let t,r=0;r<h;r++)t=e[r],t&&"object"==typeof t&&(p=t[d],p&&(p.ownKey=r));for(y=0,b=c.length;y<b;y++)v=c[y],v&&"object"==typeof v&&(p=v[d],p&&(c[y]=p.detach()));const w=[];let g;for(g=0;g<i;g++)g<a?w.push(new P(f,[s+g],e[s+g],c[g],this)):w.push(new P(u,[s+g],void 0,c[g],this));for(;g<a;g++)w.push(new P(l,[s+g],e[s+g],void 0,this));return O(t,w),c}},k={reverse:A,sort:E,fill:S,copyWithin:H,set:function(t,e){const r=this[d],n=r.target,o=t.length,s=n.slice(0);e=e||0,n.set(t,e);const i=new Array(o);for(let t=e;t<o+e;t++)i[t-e]=new P(f,[t],n[t],s[t],this);O(r,i)}};class P{constructor(t,e,r,n,o){this.type=t,this.path=e,this.value=r,this.oldValue=n,this.object=o}}class T{constructor(t,e){const{target:r,parent:n,ownKey:o}=t;n&&void 0!==o?(this.parent=n,this.ownKey=o):(this.parent=null,this.ownKey=null);const s=e(r,this);this.observers=[],this.revocable=Proxy.revocable(s,this),this.proxy=this.revocable.proxy,this.target=s,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if("object"!=typeof t)throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter((t=>!(t in b)));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}return{}}detach(){return this.parent=null,this.target}set(t,e,r){let n=t[e];if(r!==n){const o=M(r,e,this);if(t[e]=o,n&&"object"==typeof n){const t=n[d];t&&(n=t.detach())}const s=void 0===n?[new P(l,[e],o,void 0,this.proxy)]:[new P(f,[e],o,n,this.proxy)];O(this,s)}return!0}deleteProperty(t,e){let r=t[e];if(delete t[e],r&&"object"==typeof r){const t=r[d];t&&(r=t.detach())}const n=[new P(u,[e],void 0,r,this.proxy)];return O(this,n),!0}}class N extends T{constructor(t){super(t,w)}}class F extends T{constructor(t){super(t,g)}get(t,e){return K[e]||t[e]}}class R extends T{constructor(t){super(t,m)}get(t,e){return k[e]||t[e]}}const $=Object.freeze({from:(t,e)=>{if(t&&"object"==typeof t){if(t[d])return t;if(Array.isArray(t))return new F({target:t,ownKey:null,parent:null,options:e}).proxy;if(ArrayBuffer.isView(t))return new R({target:t,ownKey:null,parent:null,options:e}).proxy;if(t instanceof Date)throw new Error(`${t} found to be one of a non-observable types`);return new N({target:t,ownKey:null,parent:null,options:e}).proxy}throw new Error("observable MAY ONLY be created from a non-null object")},isObservable:t=>!(!t||!t[d]),observe:(t,e,r)=>{if(!$.isObservable(t))throw new Error("invalid observable parameter");if("function"!=typeof e)throw new Error(`observer MUST be a function, got '${e}'`);const n=t[d].observers;n.some((t=>t[0]===e))?console.warn("observer may be bound to an observable only once; will NOT rebind"):n.push([e,v(r)])},unobserve:(t,...e)=>{if(!$.isObservable(t))throw new Error("invalid observable parameter");const r=t[d].observers;let n=r.length;if(n)if(e.length)for(;n;){e.indexOf(r[--n][0])>=0&&r.splice(n,1)}else r.splice(0)}});var Y=function(){var t=this;this.on=function(e,r){return t.handlers[e]=t.handlers[e]||[],t.handlers[e].push(r),t},this.off=function(e,r){var n=t.handlers[e];if(n)for(var o=0;o<n.length;o++)n[o]===r&&n.splice(o,1);return t},this.callEmitFromMT=function(){this.func.apply(null,this.args?this.args:[])},this.emit=function(e,r){if(t.handlers[e])for(var n=0;n<t.handlers[e].length;n++)try{queueMicrotask(t.callEmitFromMT.bind({func:t.handlers[e][n],args:r}))}catch(t){console.log(t)}return t},this.clear=function(){t.handlers={}},this.handlers={}},z=function(t){function e(e){var r=t.call(this)||this;return Object.keys(e.property).forEach((function(t){r.on(t,(function(r){try{e.property[t].apply(e.state,[r])}catch(t){console.log(t)}}))})),r}return i(e,t),e}(Y),D=function(t){function e(e,r){var n,o,s=this;return(s=t.call(this)||this).middlewares=[],s._sendHistory=[],s.watch=function(t){return c(s,void 0,void 0,(function(){var e,r,n=this;return h(this,(function(o){switch(o.label){case 0:return e=performance.now(),[4,this.executeMiddlewares(t,(function(){for(var e,r=function(t){var r=t.path.filter((function(t){return"number"!=typeof t}));if(null===(e=n._options)||void 0===e?void 0:e.deep){var o="";r.forEach((function(e){o+=e+".",n.emit(o.substring(0,o.length-1),[t.object])}))}else{var s=r.join(".");n.emit(s,[t.object])}},o=0,s=t;o<s.length;o++){r(s[o])}}))];case 1:return o.sent(),"development"===process.env.NODE_ENV&&(r=performance.now()-e)>33.34&&console.warn("[x-view-model] Slow state update detected (".concat(r.toFixed(2),"ms)"),t),[2]}}))}))},s._property=e,s._options=r,s._reference=0,s._observable=$.from(a({},s._property),{async:!0}),s._started=!1,s.services=new z(s),s._historyHandler=(null===(n=null==r?void 0:r.history)||void 0===n?void 0:n.handler)||function(){},s._historyMaxSize=(null===(o=null==r?void 0:r.history)||void 0===o?void 0:o.maxSize)||100,s.middlewares=(null==r?void 0:r.middlewares)||[],s}return i(e,t),e.prototype.use=function(t){return this.middlewares.push(t),this},e.prototype.executeMiddlewares=function(t,e){return c(this,void 0,void 0,(function(){var r=this;return h(this,(function(n){switch(n.label){case 0:return 0===this.middlewares.length?(e(),[2]):[4,this.middlewares.reduceRight((function(e,n){return function(){return n(t,e,r.state)}}),e)()];case 1:return n.sent(),[2]}}))}))},Object.defineProperty(e.prototype,"state",{get:function(){return this._observable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"property",{get:function(){return this._property},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"reference",{get:function(){return this._reference},set:function(t){this._reference=t,this._reference>0?this.start():this.stop()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._options&&this._options.name?this._options.name:"unnamed"},enumerable:!1,configurable:!0}),e.prototype.increaseReference=function(){this.reference++},e.prototype.decreaseReference=function(){this.reference--},e.prototype.start=function(){if(!this._started)return $.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.stop=function(){if(this._started)return $.unobserve(this._observable),this._observable=$.from(a({},this._property)),this._started=!1,this},e.prototype.pause=function(){if(this._started)return $.unobserve(this._observable),this},e.prototype.restart=function(){return $.unobserve(this._observable),this._observable=$.from(a({},this._property)),$.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.snapshot=function(){this.pause();var t=JSON.stringify(this._observable);return this.start(),t},e.prototype.rebase=function(t){var e="string"==typeof t?JSON.parse(t):t;return this._property=a(a({},this._property),e),this},e.prototype.restore=function(t){this.pause();var e="string"==typeof t?JSON.parse(t):t;return this._observable=$.from(a(a({},this._property),e)),this.start(),this},e.prototype.addHistory=function(t){return c(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return this._historyHandler?[4,Promise.resolve(this._historyHandler(t,this.state))]:[3,2];case 1:e.sent(),e.label=2;case 2:return this._sendHistory.push(t),this._sendHistory.length>this._historyMaxSize&&(this._sendHistory=this._sendHistory.slice(-this._historyMaxSize)),[2]}}))}))},e.prototype.send=function(t,e,r){return void 0===r&&(r=!1),c(this,void 0,void 0,(function(){var n,o,s;return h(this,(function(i){switch(i.label){case 0:if(n={name:t,payload:e,timestamp:Date.now()},!r)return[3,7];i.label=1;case 1:return i.trys.push([1,4,,6]),[4,this.property[t].apply(this.state,[e])];case 2:return o=i.sent(),n.result=o,[4,this.addHistory(n)];case 3:return i.sent(),[2,o];case 4:return s=i.sent(),n.error=s,[4,this.addHistory(n)];case 5:throw i.sent(),s;case 6:return[3,9];case 7:return this.services.emit(t,[e]),[4,this.addHistory(n)];case 8:return i.sent(),[2,void 0];case 9:return[2]}}))}))},e.prototype.getSendHistory=function(){return this._sendHistory},e.prototype.clearSendHistory=function(){this._sendHistory=[]},e}(Y),U=function(t,e,r){return{context:new D(t,e),ref:r}},V=function(s,i){var a,c,h;o("".concat(Date.now(),"-").concat(Math.random())).current,o((null===(h=null===(c=null===(a=(new Error).stack)||void 0===a?void 0:a.split("\n")[2])||void 0===c?void 0:c.trim())||void 0===h?void 0:h.split(" ")[1])||"Unknown").current;var l=function(o,s){var i=t(0);i[0];var a=i[1],c=e((function(t){a((function(t){return t+1}))}),[]);return r((function(){s.increaseReference(),Array.isArray(o)?o.forEach((function(t){s.on(t,c)})):s.on(o,c)}),[s]),n((function(){return function(){s.decreaseReference(),Array.isArray(o)?o.forEach((function(t){s.off(t,c)})):s.off(o,c)}}),[s]),s.state}(i,s.context);return[l,s.context.send.bind(s.context),s.ref]},W=function(t,e,n){var o=V(t,n),s=o[0],i=o[1],a=o[2];return[r((function(){return e(s)}),[s,e]),i,a]},B=function(t,e){var r=V(t,e);return[r[0],r[1],r[2]]};export{D as PropertyHandler,U as registViewModel,W as useComputedViewModel,B as useMemoizedViewModel,V as useViewModel};
//# sourceMappingURL=index.esm.min.js.map

@@ -1218,3 +1218,3 @@ 'use strict';

var state = useInterfaceHandle(keys, vm.context);
return [state, vm.context.send, vm.ref];
return [state, vm.context.send.bind(vm.context), vm.ref];
};

@@ -1221,0 +1221,0 @@ var useComputedViewModel = function (vm, selector, keys) {

@@ -15,3 +15,3 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},e(t,r)};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function o(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{c(n.next(t))}catch(t){s(t)}}function a(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}c((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}const i="insert",a="update",c="delete",h="reverse",l="shuffle",u=Symbol.for("object-observer-meta-key-0"),f={async:1},p=t=>{if(!t||"object"!=typeof t)return null;const e={},r=[];for(const[n,o]of Object.entries(t))if("path"===n){if("string"!=typeof o||""===o)throw new Error('"path" option, if/when provided, MUST be a non-empty string');e[n]=o}else if("pathsOf"===n){if(t.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if("string"!=typeof o)throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');e[n]=t.pathsOf.split(".").filter(Boolean)}else if("pathsFrom"===n){if(t.path||t.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if("string"!=typeof o||""===o)throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');e[n]=o}else r.push(n);if(r.length)throw new Error(`'${r.join(", ")}' is/are not a valid observer option/s`);return e},y=(t,e)=>{const r={};r[u]=e;for(const n in t)r[n]=_(t[n],n,e);return r},d=(t,e)=>{let r=t.length;const n=new Array(r);n[u]=e;for(let o=0;o<r;o++)n[o]=_(t[o],o,e);return n},b=(t,e)=>(t[u]=e,t),v=(t,e)=>{if(null===t)return e;let r=e;if(t.path){const n=t.path;r=e.filter((t=>t.path.join(".")===n))}else if(t.pathsOf){const n=t.pathsOf,o=n.join(".");r=e.filter((t=>(t.path.length===n.length+1||t.path.length===n.length&&(t.type===h||t.type===l))&&t.path.join(".").startsWith(o)))}else if(t.pathsFrom){const n=t.pathsFrom;r=e.filter((t=>t.path.join(".").startsWith(n)))}return r},w=(t,e)=>{try{t(e)}catch(r){console.error(`failed to notify listener ${t} with ${e}`,r)}},g=function(){const t=this.batches;this.batches=[];for(const[e,r]of t)w(e,r)},m=(t,e)=>{let r,n,o,s,i,a,c=t;const h=e.length;do{for(r=c.options.async,n=c.observers,a=n.length;a--;)if([o,s]=n[a],i=v(s,e),i.length)if(r){let t;0===c.batches.length&&queueMicrotask(g.bind(c));for(const e of c.batches)if(e[0]===o){t=e;break}t||(t=[o,[]],c.batches.push(t)),Array.prototype.push.apply(t[1],i)}else w(o,i);const t=c.parent;if(t){for(let t=0;t<h;t++){const r=e[t];e[t]=new S(r.type,[c.ownKey,...r.path],r.value,r.oldValue,r.object)}c=t}else c=null}while(c)},_=(t,e,r)=>"object"!=typeof t||null===t?t:Array.isArray(t)?new k({target:t,ownKey:e,parent:r}).proxy:ArrayBuffer.isView(t)?new P({target:t,ownKey:e,parent:r}).proxy:t instanceof Date?t:new K({target:t,ownKey:e,parent:r}).proxy,j=function(){const t=this[u],e=t.target;let r,n,o;for(e.reverse(),r=0,n=e.length;r<n;r++)if(o=e[r],o&&"object"==typeof o){const t=o[u];t&&(t.ownKey=r)}const s=[new S(h,[],void 0,void 0,this)];return m(t,s),this},x=function(t){const e=this[u],r=e.target;let n,o,s;for(r.sort(t),n=0,o=r.length;n<o;n++)if(s=r[n],s&&"object"==typeof s){const t=s[u];t&&(t.ownKey=n)}const i=[new S(l,[],void 0,void 0,this)];return m(e,i),this},O=function(t,e,r){const n=this[u],o=n.target,s=[],c=o.length,h=o.slice(0);if(e=void 0===e?0:e<0?Math.max(c+e,0):Math.min(e,c),r=void 0===r?c:r<0?Math.max(c+r,0):Math.min(r,c),e<c&&r>e){let c;o.fill(t,e,r);for(let t,l,f=e;f<r;f++)t=o[f],o[f]=_(t,f,n),f in h?(l=h[f],l&&"object"==typeof l&&(c=l[u],c&&(l=c.detach())),s.push(new S(a,[f],o[f],l,this))):s.push(new S(i,[f],o[f],void 0,this));m(n,s)}return this},M=function(t,e,r){const n=this[u],o=n.target,s=o.length;t=t<0?Math.max(s+t,0):t,e=void 0===e?0:e<0?Math.max(s+e,0):Math.min(e,s),r=void 0===r?s:r<0?Math.max(s+r,0):Math.min(r,s);const i=Math.min(r-e,s-t);if(t<s&&t!==e&&i>0){const s=o.slice(0),c=[];o.copyWithin(t,e,r);for(let e,r,h,l=t;l<t+i;l++)e=o[l],e&&"object"==typeof e&&(e=_(e,l,n),o[l]=e),r=s[l],r&&"object"==typeof r&&(h=r[u],h&&(r=h.detach())),"object"!=typeof e&&e===r||c.push(new S(a,[l],e,r,this));m(n,c)}return this},E={pop:function(){const t=this[u],e=t.target,r=e.length-1;let n=e.pop();if(n&&"object"==typeof n){const t=n[u];t&&(n=t.detach())}const o=[new S(c,[r],void 0,n,this)];return m(t,o),n},push:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=_(arguments[e],o+e,t);const s=Reflect.apply(e.push,e,n),a=[];for(let t=o,r=e.length;t<r;t++)a[t-o]=new S(i,[t],e[t],void 0,this);return m(t,a),s},shift:function(){const t=this[u],e=t.target;let r,n,o,s,i;for(r=e.shift(),r&&"object"==typeof r&&(i=r[u],i&&(r=i.detach())),n=0,o=e.length;n<o;n++)s=e[n],s&&"object"==typeof s&&(i=s[u],i&&(i.ownKey=n));const a=[new S(c,[0],void 0,r,this)];return m(t,a),r},unshift:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r);for(let e=0;e<r;e++)n[e]=_(arguments[e],e,t);const o=Reflect.apply(e.unshift,e,n);for(let t,r=0,n=e.length;r<n;r++)if(t=e[r],t&&"object"==typeof t){const e=t[u];e&&(e.ownKey=r)}const s=n.length,a=new Array(s);for(let t=0;t<s;t++)a[t]=new S(i,[t],e[t],void 0,this);return m(t,a),o},reverse:j,sort:x,fill:O,copyWithin:M,splice:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=_(arguments[e],e,t);const s=0===r?0:n[0]<0?o+n[0]:n[0],h=r<2?o-s:n[1],l=Math.max(r-2,0),f=Reflect.apply(e.splice,e,n),p=e.length;let y,d,b,v;for(let t,r=0;r<p;r++)t=e[r],t&&"object"==typeof t&&(y=t[u],y&&(y.ownKey=r));for(d=0,b=f.length;d<b;d++)v=f[d],v&&"object"==typeof v&&(y=v[u],y&&(f[d]=y.detach()));const w=[];let g;for(g=0;g<h;g++)g<l?w.push(new S(a,[s+g],e[s+g],f[g],this)):w.push(new S(c,[s+g],void 0,f[g],this));for(;g<l;g++)w.push(new S(i,[s+g],e[s+g],void 0,this));return m(t,w),f}},A={reverse:j,sort:x,fill:O,copyWithin:M,set:function(t,e){const r=this[u],n=r.target,o=t.length,s=n.slice(0);e=e||0,n.set(t,e);const i=new Array(o);for(let t=e;t<o+e;t++)i[t-e]=new S(a,[t],n[t],s[t],this);m(r,i)}};class S{constructor(t,e,r,n,o){this.type=t,this.path=e,this.value=r,this.oldValue=n,this.object=o}}class H{constructor(t,e){const{target:r,parent:n,ownKey:o}=t;n&&void 0!==o?(this.parent=n,this.ownKey=o):(this.parent=null,this.ownKey=null);const s=e(r,this);this.observers=[],this.revocable=Proxy.revocable(s,this),this.proxy=this.revocable.proxy,this.target=s,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if("object"!=typeof t)throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter((t=>!(t in f)));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}return{}}detach(){return this.parent=null,this.target}set(t,e,r){let n=t[e];if(r!==n){const o=_(r,e,this);if(t[e]=o,n&&"object"==typeof n){const t=n[u];t&&(n=t.detach())}const s=void 0===n?[new S(i,[e],o,void 0,this.proxy)]:[new S(a,[e],o,n,this.proxy)];m(this,s)}return!0}deleteProperty(t,e){let r=t[e];if(delete t[e],r&&"object"==typeof r){const t=r[u];t&&(r=t.detach())}const n=[new S(c,[e],void 0,r,this.proxy)];return m(this,n),!0}}class K extends H{constructor(t){super(t,y)}}class k extends H{constructor(t){super(t,d)}get(t,e){return E[e]||t[e]}}class P extends H{constructor(t){super(t,b)}get(t,e){return A[e]||t[e]}}const R=Object.freeze({from:(t,e)=>{if(t&&"object"==typeof t){if(t[u])return t;if(Array.isArray(t))return new k({target:t,ownKey:null,parent:null,options:e}).proxy;if(ArrayBuffer.isView(t))return new P({target:t,ownKey:null,parent:null,options:e}).proxy;if(t instanceof Date)throw new Error(`${t} found to be one of a non-observable types`);return new K({target:t,ownKey:null,parent:null,options:e}).proxy}throw new Error("observable MAY ONLY be created from a non-null object")},isObservable:t=>!(!t||!t[u]),observe:(t,e,r)=>{if(!R.isObservable(t))throw new Error("invalid observable parameter");if("function"!=typeof e)throw new Error(`observer MUST be a function, got '${e}'`);const n=t[u].observers;n.some((t=>t[0]===e))?console.warn("observer may be bound to an observable only once; will NOT rebind"):n.push([e,p(r)])},unobserve:(t,...e)=>{if(!R.isObservable(t))throw new Error("invalid observable parameter");const r=t[u].observers;let n=r.length;if(n)if(e.length)for(;n;){e.indexOf(r[--n][0])>=0&&r.splice(n,1)}else r.splice(0)}});var T=function(){var t=this;this.on=function(e,r){return t.handlers[e]=t.handlers[e]||[],t.handlers[e].push(r),t},this.off=function(e,r){var n=t.handlers[e];if(n)for(var o=0;o<n.length;o++)n[o]===r&&n.splice(o,1);return t},this.callEmitFromMT=function(){this.func.apply(null,this.args?this.args:[])},this.emit=function(e,r){if(t.handlers[e])for(var n=0;n<t.handlers[e].length;n++)try{queueMicrotask(t.callEmitFromMT.bind({func:t.handlers[e][n],args:r}))}catch(t){console.log(t)}return t},this.clear=function(){t.handlers={}},this.handlers={}},N=function(t){function e(e){var r=t.call(this)||this;return Object.keys(e.property).forEach((function(t){r.on(t,(function(r){try{e.property[t].apply(e.state,[r])}catch(t){console.log(t)}}))})),r}return r(e,t),e}(T),V=function(t){function e(e,r){var i,a,c=this;return(c=t.call(this)||this).middlewares=[],c._sendHistory=[],c.watch=function(t){return o(c,void 0,void 0,(function(){var e,r,n=this;return s(this,(function(o){switch(o.label){case 0:return e=performance.now(),[4,this.executeMiddlewares(t,(function(){for(var e,r=function(t){var r=t.path.filter((function(t){return"number"!=typeof t}));if(null===(e=n._options)||void 0===e?void 0:e.deep){var o="";r.forEach((function(e){o+=e+".",n.emit(o.substring(0,o.length-1),[t.object])}))}else{var s=r.join(".");n.emit(s,[t.object])}},o=0,s=t;o<s.length;o++){r(s[o])}}))];case 1:return o.sent(),"development"===process.env.NODE_ENV&&(r=performance.now()-e)>33.34&&console.warn("[x-view-model] Slow state update detected (".concat(r.toFixed(2),"ms)"),t),[2]}}))}))},c._property=e,c._options=r,c._reference=0,c._observable=R.from(n({},c._property),{async:!0}),c._started=!1,c.services=new N(c),c._historyHandler=(null===(i=null==r?void 0:r.history)||void 0===i?void 0:i.handler)||function(){},c._historyMaxSize=(null===(a=null==r?void 0:r.history)||void 0===a?void 0:a.maxSize)||100,c.middlewares=(null==r?void 0:r.middlewares)||[],c}return r(e,t),e.prototype.use=function(t){return this.middlewares.push(t),this},e.prototype.executeMiddlewares=function(t,e){return o(this,void 0,void 0,(function(){var r=this;return s(this,(function(n){switch(n.label){case 0:return 0===this.middlewares.length?(e(),[2]):[4,this.middlewares.reduceRight((function(e,n){return function(){return n(t,e,r.state)}}),e)()];case 1:return n.sent(),[2]}}))}))},Object.defineProperty(e.prototype,"state",{get:function(){return this._observable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"property",{get:function(){return this._property},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"reference",{get:function(){return this._reference},set:function(t){this._reference=t,this._reference>0?this.start():this.stop()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._options&&this._options.name?this._options.name:"unnamed"},enumerable:!1,configurable:!0}),e.prototype.increaseReference=function(){this.reference++},e.prototype.decreaseReference=function(){this.reference--},e.prototype.start=function(){if(!this._started)return R.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.stop=function(){if(this._started)return R.unobserve(this._observable),this._observable=R.from(n({},this._property)),this._started=!1,this},e.prototype.pause=function(){if(this._started)return R.unobserve(this._observable),this},e.prototype.restart=function(){return R.unobserve(this._observable),this._observable=R.from(n({},this._property)),R.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.snapshot=function(){this.pause();var t=JSON.stringify(this._observable);return this.start(),t},e.prototype.rebase=function(t){var e="string"==typeof t?JSON.parse(t):t;return this._property=n(n({},this._property),e),this},e.prototype.restore=function(t){this.pause();var e="string"==typeof t?JSON.parse(t):t;return this._observable=R.from(n(n({},this._property),e)),this.start(),this},e.prototype.addHistory=function(t){return o(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return this._historyHandler?[4,Promise.resolve(this._historyHandler(t,this.state))]:[3,2];case 1:e.sent(),e.label=2;case 2:return this._sendHistory.push(t),this._sendHistory.length>this._historyMaxSize&&(this._sendHistory=this._sendHistory.slice(-this._historyMaxSize)),[2]}}))}))},e.prototype.send=function(t,e,r){return void 0===r&&(r=!1),o(this,void 0,void 0,(function(){var n,o,i;return s(this,(function(s){switch(s.label){case 0:if(n={name:t,payload:e,timestamp:Date.now()},!r)return[3,7];s.label=1;case 1:return s.trys.push([1,4,,6]),[4,this.property[t].apply(this.state,[e])];case 2:return o=s.sent(),n.result=o,[4,this.addHistory(n)];case 3:return s.sent(),[2,o];case 4:return i=s.sent(),n.error=i,[4,this.addHistory(n)];case 5:throw s.sent(),i;case 6:return[3,9];case 7:return this.services.emit(t,[e]),[4,this.addHistory(n)];case 8:return s.sent(),[2,void 0];case 9:return[2]}}))}))},e.prototype.getSendHistory=function(){return this._sendHistory},e.prototype.clearSendHistory=function(){this._sendHistory=[]},e}(T),F=function(e,r){var n,o,s;t.useRef("".concat(Date.now(),"-").concat(Math.random())).current,t.useRef((null===(s=null===(o=null===(n=(new Error).stack)||void 0===n?void 0:n.split("\n")[2])||void 0===o?void 0:o.trim())||void 0===s?void 0:s.split(" ")[1])||"Unknown").current;var i=function(e,r){var n=t.useState(0);n[0];var o=n[1],s=t.useCallback((function(t){o((function(t){return t+1}))}),[]);return t.useMemo((function(){r.increaseReference(),Array.isArray(e)?e.forEach((function(t){r.on(t,s)})):r.on(e,s)}),[r]),t.useEffect((function(){return function(){r.decreaseReference(),Array.isArray(e)?e.forEach((function(t){r.off(t,s)})):r.off(e,s)}}),[r]),r.state}(r,e.context);return[i,e.context.send,e.ref]};exports.PropertyHandler=V,exports.registViewModel=function(t,e,r){return{context:new V(t,e),ref:r}},exports.useComputedViewModel=function(e,r,n){var o=F(e,n),s=o[0],i=o[1],a=o[2];return[t.useMemo((function(){return r(s)}),[s,r]),i,a]},exports.useMemoizedViewModel=function(t,e){var r=F(t,e);return[r[0],r[1],r[2]]},exports.useViewModel=F;
***************************************************************************** */function r(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function o(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{c(n.next(t))}catch(t){s(t)}}function a(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}c((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}const i="insert",a="update",c="delete",h="reverse",l="shuffle",u=Symbol.for("object-observer-meta-key-0"),f={async:1},p=t=>{if(!t||"object"!=typeof t)return null;const e={},r=[];for(const[n,o]of Object.entries(t))if("path"===n){if("string"!=typeof o||""===o)throw new Error('"path" option, if/when provided, MUST be a non-empty string');e[n]=o}else if("pathsOf"===n){if(t.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if("string"!=typeof o)throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');e[n]=t.pathsOf.split(".").filter(Boolean)}else if("pathsFrom"===n){if(t.path||t.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if("string"!=typeof o||""===o)throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');e[n]=o}else r.push(n);if(r.length)throw new Error(`'${r.join(", ")}' is/are not a valid observer option/s`);return e},y=(t,e)=>{const r={};r[u]=e;for(const n in t)r[n]=_(t[n],n,e);return r},d=(t,e)=>{let r=t.length;const n=new Array(r);n[u]=e;for(let o=0;o<r;o++)n[o]=_(t[o],o,e);return n},b=(t,e)=>(t[u]=e,t),v=(t,e)=>{if(null===t)return e;let r=e;if(t.path){const n=t.path;r=e.filter((t=>t.path.join(".")===n))}else if(t.pathsOf){const n=t.pathsOf,o=n.join(".");r=e.filter((t=>(t.path.length===n.length+1||t.path.length===n.length&&(t.type===h||t.type===l))&&t.path.join(".").startsWith(o)))}else if(t.pathsFrom){const n=t.pathsFrom;r=e.filter((t=>t.path.join(".").startsWith(n)))}return r},w=(t,e)=>{try{t(e)}catch(r){console.error(`failed to notify listener ${t} with ${e}`,r)}},g=function(){const t=this.batches;this.batches=[];for(const[e,r]of t)w(e,r)},m=(t,e)=>{let r,n,o,s,i,a,c=t;const h=e.length;do{for(r=c.options.async,n=c.observers,a=n.length;a--;)if([o,s]=n[a],i=v(s,e),i.length)if(r){let t;0===c.batches.length&&queueMicrotask(g.bind(c));for(const e of c.batches)if(e[0]===o){t=e;break}t||(t=[o,[]],c.batches.push(t)),Array.prototype.push.apply(t[1],i)}else w(o,i);const t=c.parent;if(t){for(let t=0;t<h;t++){const r=e[t];e[t]=new S(r.type,[c.ownKey,...r.path],r.value,r.oldValue,r.object)}c=t}else c=null}while(c)},_=(t,e,r)=>"object"!=typeof t||null===t?t:Array.isArray(t)?new k({target:t,ownKey:e,parent:r}).proxy:ArrayBuffer.isView(t)?new P({target:t,ownKey:e,parent:r}).proxy:t instanceof Date?t:new K({target:t,ownKey:e,parent:r}).proxy,j=function(){const t=this[u],e=t.target;let r,n,o;for(e.reverse(),r=0,n=e.length;r<n;r++)if(o=e[r],o&&"object"==typeof o){const t=o[u];t&&(t.ownKey=r)}const s=[new S(h,[],void 0,void 0,this)];return m(t,s),this},x=function(t){const e=this[u],r=e.target;let n,o,s;for(r.sort(t),n=0,o=r.length;n<o;n++)if(s=r[n],s&&"object"==typeof s){const t=s[u];t&&(t.ownKey=n)}const i=[new S(l,[],void 0,void 0,this)];return m(e,i),this},O=function(t,e,r){const n=this[u],o=n.target,s=[],c=o.length,h=o.slice(0);if(e=void 0===e?0:e<0?Math.max(c+e,0):Math.min(e,c),r=void 0===r?c:r<0?Math.max(c+r,0):Math.min(r,c),e<c&&r>e){let c;o.fill(t,e,r);for(let t,l,f=e;f<r;f++)t=o[f],o[f]=_(t,f,n),f in h?(l=h[f],l&&"object"==typeof l&&(c=l[u],c&&(l=c.detach())),s.push(new S(a,[f],o[f],l,this))):s.push(new S(i,[f],o[f],void 0,this));m(n,s)}return this},M=function(t,e,r){const n=this[u],o=n.target,s=o.length;t=t<0?Math.max(s+t,0):t,e=void 0===e?0:e<0?Math.max(s+e,0):Math.min(e,s),r=void 0===r?s:r<0?Math.max(s+r,0):Math.min(r,s);const i=Math.min(r-e,s-t);if(t<s&&t!==e&&i>0){const s=o.slice(0),c=[];o.copyWithin(t,e,r);for(let e,r,h,l=t;l<t+i;l++)e=o[l],e&&"object"==typeof e&&(e=_(e,l,n),o[l]=e),r=s[l],r&&"object"==typeof r&&(h=r[u],h&&(r=h.detach())),"object"!=typeof e&&e===r||c.push(new S(a,[l],e,r,this));m(n,c)}return this},E={pop:function(){const t=this[u],e=t.target,r=e.length-1;let n=e.pop();if(n&&"object"==typeof n){const t=n[u];t&&(n=t.detach())}const o=[new S(c,[r],void 0,n,this)];return m(t,o),n},push:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=_(arguments[e],o+e,t);const s=Reflect.apply(e.push,e,n),a=[];for(let t=o,r=e.length;t<r;t++)a[t-o]=new S(i,[t],e[t],void 0,this);return m(t,a),s},shift:function(){const t=this[u],e=t.target;let r,n,o,s,i;for(r=e.shift(),r&&"object"==typeof r&&(i=r[u],i&&(r=i.detach())),n=0,o=e.length;n<o;n++)s=e[n],s&&"object"==typeof s&&(i=s[u],i&&(i.ownKey=n));const a=[new S(c,[0],void 0,r,this)];return m(t,a),r},unshift:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r);for(let e=0;e<r;e++)n[e]=_(arguments[e],e,t);const o=Reflect.apply(e.unshift,e,n);for(let t,r=0,n=e.length;r<n;r++)if(t=e[r],t&&"object"==typeof t){const e=t[u];e&&(e.ownKey=r)}const s=n.length,a=new Array(s);for(let t=0;t<s;t++)a[t]=new S(i,[t],e[t],void 0,this);return m(t,a),o},reverse:j,sort:x,fill:O,copyWithin:M,splice:function(){const t=this[u],e=t.target,r=arguments.length,n=new Array(r),o=e.length;for(let e=0;e<r;e++)n[e]=_(arguments[e],e,t);const s=0===r?0:n[0]<0?o+n[0]:n[0],h=r<2?o-s:n[1],l=Math.max(r-2,0),f=Reflect.apply(e.splice,e,n),p=e.length;let y,d,b,v;for(let t,r=0;r<p;r++)t=e[r],t&&"object"==typeof t&&(y=t[u],y&&(y.ownKey=r));for(d=0,b=f.length;d<b;d++)v=f[d],v&&"object"==typeof v&&(y=v[u],y&&(f[d]=y.detach()));const w=[];let g;for(g=0;g<h;g++)g<l?w.push(new S(a,[s+g],e[s+g],f[g],this)):w.push(new S(c,[s+g],void 0,f[g],this));for(;g<l;g++)w.push(new S(i,[s+g],e[s+g],void 0,this));return m(t,w),f}},A={reverse:j,sort:x,fill:O,copyWithin:M,set:function(t,e){const r=this[u],n=r.target,o=t.length,s=n.slice(0);e=e||0,n.set(t,e);const i=new Array(o);for(let t=e;t<o+e;t++)i[t-e]=new S(a,[t],n[t],s[t],this);m(r,i)}};class S{constructor(t,e,r,n,o){this.type=t,this.path=e,this.value=r,this.oldValue=n,this.object=o}}class H{constructor(t,e){const{target:r,parent:n,ownKey:o}=t;n&&void 0!==o?(this.parent=n,this.ownKey=o):(this.parent=null,this.ownKey=null);const s=e(r,this);this.observers=[],this.revocable=Proxy.revocable(s,this),this.proxy=this.revocable.proxy,this.target=s,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if("object"!=typeof t)throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter((t=>!(t in f)));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}return{}}detach(){return this.parent=null,this.target}set(t,e,r){let n=t[e];if(r!==n){const o=_(r,e,this);if(t[e]=o,n&&"object"==typeof n){const t=n[u];t&&(n=t.detach())}const s=void 0===n?[new S(i,[e],o,void 0,this.proxy)]:[new S(a,[e],o,n,this.proxy)];m(this,s)}return!0}deleteProperty(t,e){let r=t[e];if(delete t[e],r&&"object"==typeof r){const t=r[u];t&&(r=t.detach())}const n=[new S(c,[e],void 0,r,this.proxy)];return m(this,n),!0}}class K extends H{constructor(t){super(t,y)}}class k extends H{constructor(t){super(t,d)}get(t,e){return E[e]||t[e]}}class P extends H{constructor(t){super(t,b)}get(t,e){return A[e]||t[e]}}const R=Object.freeze({from:(t,e)=>{if(t&&"object"==typeof t){if(t[u])return t;if(Array.isArray(t))return new k({target:t,ownKey:null,parent:null,options:e}).proxy;if(ArrayBuffer.isView(t))return new P({target:t,ownKey:null,parent:null,options:e}).proxy;if(t instanceof Date)throw new Error(`${t} found to be one of a non-observable types`);return new K({target:t,ownKey:null,parent:null,options:e}).proxy}throw new Error("observable MAY ONLY be created from a non-null object")},isObservable:t=>!(!t||!t[u]),observe:(t,e,r)=>{if(!R.isObservable(t))throw new Error("invalid observable parameter");if("function"!=typeof e)throw new Error(`observer MUST be a function, got '${e}'`);const n=t[u].observers;n.some((t=>t[0]===e))?console.warn("observer may be bound to an observable only once; will NOT rebind"):n.push([e,p(r)])},unobserve:(t,...e)=>{if(!R.isObservable(t))throw new Error("invalid observable parameter");const r=t[u].observers;let n=r.length;if(n)if(e.length)for(;n;){e.indexOf(r[--n][0])>=0&&r.splice(n,1)}else r.splice(0)}});var T=function(){var t=this;this.on=function(e,r){return t.handlers[e]=t.handlers[e]||[],t.handlers[e].push(r),t},this.off=function(e,r){var n=t.handlers[e];if(n)for(var o=0;o<n.length;o++)n[o]===r&&n.splice(o,1);return t},this.callEmitFromMT=function(){this.func.apply(null,this.args?this.args:[])},this.emit=function(e,r){if(t.handlers[e])for(var n=0;n<t.handlers[e].length;n++)try{queueMicrotask(t.callEmitFromMT.bind({func:t.handlers[e][n],args:r}))}catch(t){console.log(t)}return t},this.clear=function(){t.handlers={}},this.handlers={}},N=function(t){function e(e){var r=t.call(this)||this;return Object.keys(e.property).forEach((function(t){r.on(t,(function(r){try{e.property[t].apply(e.state,[r])}catch(t){console.log(t)}}))})),r}return r(e,t),e}(T),V=function(t){function e(e,r){var i,a,c=this;return(c=t.call(this)||this).middlewares=[],c._sendHistory=[],c.watch=function(t){return o(c,void 0,void 0,(function(){var e,r,n=this;return s(this,(function(o){switch(o.label){case 0:return e=performance.now(),[4,this.executeMiddlewares(t,(function(){for(var e,r=function(t){var r=t.path.filter((function(t){return"number"!=typeof t}));if(null===(e=n._options)||void 0===e?void 0:e.deep){var o="";r.forEach((function(e){o+=e+".",n.emit(o.substring(0,o.length-1),[t.object])}))}else{var s=r.join(".");n.emit(s,[t.object])}},o=0,s=t;o<s.length;o++){r(s[o])}}))];case 1:return o.sent(),"development"===process.env.NODE_ENV&&(r=performance.now()-e)>33.34&&console.warn("[x-view-model] Slow state update detected (".concat(r.toFixed(2),"ms)"),t),[2]}}))}))},c._property=e,c._options=r,c._reference=0,c._observable=R.from(n({},c._property),{async:!0}),c._started=!1,c.services=new N(c),c._historyHandler=(null===(i=null==r?void 0:r.history)||void 0===i?void 0:i.handler)||function(){},c._historyMaxSize=(null===(a=null==r?void 0:r.history)||void 0===a?void 0:a.maxSize)||100,c.middlewares=(null==r?void 0:r.middlewares)||[],c}return r(e,t),e.prototype.use=function(t){return this.middlewares.push(t),this},e.prototype.executeMiddlewares=function(t,e){return o(this,void 0,void 0,(function(){var r=this;return s(this,(function(n){switch(n.label){case 0:return 0===this.middlewares.length?(e(),[2]):[4,this.middlewares.reduceRight((function(e,n){return function(){return n(t,e,r.state)}}),e)()];case 1:return n.sent(),[2]}}))}))},Object.defineProperty(e.prototype,"state",{get:function(){return this._observable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"property",{get:function(){return this._property},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"reference",{get:function(){return this._reference},set:function(t){this._reference=t,this._reference>0?this.start():this.stop()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._options&&this._options.name?this._options.name:"unnamed"},enumerable:!1,configurable:!0}),e.prototype.increaseReference=function(){this.reference++},e.prototype.decreaseReference=function(){this.reference--},e.prototype.start=function(){if(!this._started)return R.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.stop=function(){if(this._started)return R.unobserve(this._observable),this._observable=R.from(n({},this._property)),this._started=!1,this},e.prototype.pause=function(){if(this._started)return R.unobserve(this._observable),this},e.prototype.restart=function(){return R.unobserve(this._observable),this._observable=R.from(n({},this._property)),R.observe(this._observable,this.watch),console.log(this.name,"started"),this._started=!0,this},e.prototype.snapshot=function(){this.pause();var t=JSON.stringify(this._observable);return this.start(),t},e.prototype.rebase=function(t){var e="string"==typeof t?JSON.parse(t):t;return this._property=n(n({},this._property),e),this},e.prototype.restore=function(t){this.pause();var e="string"==typeof t?JSON.parse(t):t;return this._observable=R.from(n(n({},this._property),e)),this.start(),this},e.prototype.addHistory=function(t){return o(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return this._historyHandler?[4,Promise.resolve(this._historyHandler(t,this.state))]:[3,2];case 1:e.sent(),e.label=2;case 2:return this._sendHistory.push(t),this._sendHistory.length>this._historyMaxSize&&(this._sendHistory=this._sendHistory.slice(-this._historyMaxSize)),[2]}}))}))},e.prototype.send=function(t,e,r){return void 0===r&&(r=!1),o(this,void 0,void 0,(function(){var n,o,i;return s(this,(function(s){switch(s.label){case 0:if(n={name:t,payload:e,timestamp:Date.now()},!r)return[3,7];s.label=1;case 1:return s.trys.push([1,4,,6]),[4,this.property[t].apply(this.state,[e])];case 2:return o=s.sent(),n.result=o,[4,this.addHistory(n)];case 3:return s.sent(),[2,o];case 4:return i=s.sent(),n.error=i,[4,this.addHistory(n)];case 5:throw s.sent(),i;case 6:return[3,9];case 7:return this.services.emit(t,[e]),[4,this.addHistory(n)];case 8:return s.sent(),[2,void 0];case 9:return[2]}}))}))},e.prototype.getSendHistory=function(){return this._sendHistory},e.prototype.clearSendHistory=function(){this._sendHistory=[]},e}(T),F=function(e,r){var n,o,s;t.useRef("".concat(Date.now(),"-").concat(Math.random())).current,t.useRef((null===(s=null===(o=null===(n=(new Error).stack)||void 0===n?void 0:n.split("\n")[2])||void 0===o?void 0:o.trim())||void 0===s?void 0:s.split(" ")[1])||"Unknown").current;var i=function(e,r){var n=t.useState(0);n[0];var o=n[1],s=t.useCallback((function(t){o((function(t){return t+1}))}),[]);return t.useMemo((function(){r.increaseReference(),Array.isArray(e)?e.forEach((function(t){r.on(t,s)})):r.on(e,s)}),[r]),t.useEffect((function(){return function(){r.decreaseReference(),Array.isArray(e)?e.forEach((function(t){r.off(t,s)})):r.off(e,s)}}),[r]),r.state}(r,e.context);return[i,e.context.send.bind(e.context),e.ref]};exports.PropertyHandler=V,exports.registViewModel=function(t,e,r){return{context:new V(t,e),ref:r}},exports.useComputedViewModel=function(e,r,n){var o=F(e,n),s=o[0],i=o[1],a=o[2];return[t.useMemo((function(){return r(s)}),[s,r]),i,a]},exports.useMemoizedViewModel=function(t,e){var r=F(t,e);return[r[0],r[1],r[2]]},exports.useViewModel=F;
//# sourceMappingURL=index.min.js.map
{
"name": "x-view-model",
"version": "3.0.7",
"version": "3.0.8",
"description": "A lightweight, type-safe MVVM state management solution for React applications. Features reactive updates, computed properties, and deep path selection with minimal bundle size.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",