@blac/core 2.0.0-rc-8 → 2.0.0-rc-10

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/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var k=Object.defineProperty;var $=(d,e,t)=>e in d?k(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var i=(d,e,t)=>$(d,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=class u{getInstance(){return u._instance||(u._instance=new l({__unsafe_ignore_singleton:!0})),u._instance}setInstance(e){u._instance=e}resetInstance(){const e=u._instance;if(u._instance=new l({__unsafe_ignore_singleton:!0}),e)for(const t of e.keepAliveBlocs)u._instance.keepAliveBlocs.add(t),u._instance.uidRegistry.set(t.uid,t)}};i(u,"_instance");let v=u,g=new v;function M(d){g=d}const r=class r{constructor(e={}){i(this,"createdAt",Date.now());i(this,"blocInstanceMap",new Map);i(this,"isolatedBlocMap",new Map);i(this,"isolatedBlocIndex",new Map);i(this,"uidRegistry",new Map);i(this,"keepAliveBlocs",new Set);i(this,"postChangesToDocument",!1);i(this,"log",(...e)=>{r.enableLog&&r.logLevel==="warn"&&console.warn(`☢️ [Blac ${this.createdAt.toString()}]`,...e),r.enableLog&&r.logLevel==="log"&&console.log(`☢️ [Blac ${this.createdAt.toString()}]`,...e)});i(this,"warn",(e,...t)=>{r.enableLog&&console.warn(`🚨 [Blac ${String(r.instance.createdAt)}]`,e,...t)});i(this,"error",(e,...t)=>{r.enableLog&&console.error(`🚨 [Blac ${String(r.instance.createdAt)}]`,e,...t)});i(this,"resetInstance",()=>{this.log("Reset Blac instance");const e=new Map(this.blocInstanceMap),t=new Map(this.isolatedBlocMap);e.forEach(s=>{!s._keepAlive&&s._disposalState==="active"&&this.disposeBloc(s)}),t.forEach(s=>{s.forEach(n=>{!n._keepAlive&&n._disposalState==="active"&&this.disposeBloc(n)})}),this.blocInstanceMap.clear(),this.isolatedBlocMap.clear(),this.isolatedBlocIndex.clear(),g.resetInstance()});i(this,"disposeBloc",e=>{if(e._disposalState!=="active"){this.log(`[${e._name}:${String(e._id)}] disposeBloc called on already disposed bloc`);return}const t=e.constructor,s=this.createBlocInstanceMapKey(e._name,e._id);this.log(`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(t.isolated)}`),e._dispose(),t.isolated?(this.unregisterIsolatedBlocInstance(e),this.blocInstanceMap.delete(s)):this.unregisterBlocInstance(e),this.log("dispatched bloc",e)});i(this,"activateBloc",e=>{if(e._disposalState!=="active"){this.log(`[${e._name}:${String(e._id)}] activateBloc called on disposed bloc. Ignoring.`);return}const t=e.constructor;(e.isIsolated?this.findIsolatedBlocInstance(t,e._id):this.findRegisteredBlocInstance(t,e._id))||(this.log(`[${e._name}:${String(e._id)}] activateBloc called. Isolated: ${String(e.isIsolated)}`),e.isIsolated?this.registerIsolatedBlocInstance(e):this.registerBlocInstance(e))});i(this,"getBloc",(e,t={})=>{const{id:s}=t,n=e,o=s??e.name;if(n.isolated){const c=this.findIsolatedBlocInstance(e,o);if(c)return c;if(t.throwIfNotFound)throw new Error(`Isolated bloc ${e.name} not found`)}else{const c=this.findRegisteredBlocInstance(e,o);if(c)return c;if(t.throwIfNotFound)throw new Error(`Registered bloc ${e.name} not found`)}const a=this.createNewBlocInstance(e,o,t);if(this.log(`[${e.name}:${String(o)}] (getBloc) No existing instance found. Creating new one.`,t,a),!a)throw new Error(`[getBloc] Failed to create bloc instance for ${e.name}. This should never happen.`);return a});i(this,"getBlocOrThrow",(e,t={})=>{const s=e.isolated,n=t.id||e.name,o=s?this.findIsolatedBlocInstance(e,n):this.findRegisteredBlocInstance(e,n);if(o)return o;throw new Error(`Bloc ${e.name} not found`)});i(this,"getAllBlocs",(e,t={})=>{const s=[];if(this.blocInstanceMap.forEach(n=>{n.constructor===e&&s.push(n)}),t.searchIsolated!==!1){const n=this.isolatedBlocMap.get(e);n&&s.push(...n.map(o=>o))}return s});i(this,"disposeKeepAliveBlocs",e=>{const t=[];for(const s of this.keepAliveBlocs)(!e||s.constructor===e)&&t.push(s);t.forEach(s=>s._dispose())});i(this,"disposeBlocs",e=>{const t=[];for(const s of this.blocInstanceMap.values())e(s)&&t.push(s);for(const s of this.isolatedBlocMap.values())for(const n of s)e(n)&&t.push(n);t.forEach(s=>s._dispose())});i(this,"getMemoryStats",()=>({totalBlocs:this.uidRegistry.size,registeredBlocs:this.blocInstanceMap.size,isolatedBlocs:Array.from(this.isolatedBlocMap.values()).reduce((e,t)=>e+t.length,0),keepAliveBlocs:this.keepAliveBlocs.size,isolatedBlocTypes:this.isolatedBlocMap.size}));i(this,"validateConsumers",()=>{for(const e of this.uidRegistry.values())e._validateConsumers(),e._consumers.size===0&&!e._keepAlive&&e._disposalState==="active"&&setTimeout(()=>{e._consumers.size===0&&!e._keepAlive&&e._disposalState==="active"&&this.disposeBloc(e)},1e3)});const{__unsafe_ignore_singleton:t=!1}=e;if(!t)return r.instance;g.setInstance(this)}static get instance(){return g.getInstance()}static get getAllBlocs(){return r.instance.getAllBlocs}static get log(){return r.instance.log}static getInstance(){return g.getInstance()}static get warn(){return r.instance.warn}static get error(){return r.instance.error}static get disposeBloc(){return r.instance.disposeBloc}createBlocInstanceMapKey(e,t){return`${e}:${String(t)}`}unregisterBlocInstance(e){const t=this.createBlocInstanceMapKey(e._name,e._id);this.blocInstanceMap.delete(t),this.uidRegistry.delete(e.uid),this.keepAliveBlocs.delete(e)}registerBlocInstance(e){const t=this.createBlocInstanceMapKey(e._name,e._id);this.blocInstanceMap.set(t,e),this.uidRegistry.set(e.uid,e),e._keepAlive&&this.keepAliveBlocs.add(e)}findRegisteredBlocInstance(e,t){if(e.isolated)return;const n=this.createBlocInstanceMapKey(e.name,t);return this.blocInstanceMap.get(n)}registerIsolatedBlocInstance(e){const t=e.constructor,s=this.isolatedBlocMap.get(t);s?s.push(e):this.isolatedBlocMap.set(t,[e]),this.isolatedBlocIndex.set(e.uid,e),this.uidRegistry.set(e.uid,e),e._keepAlive&&this.keepAliveBlocs.add(e)}unregisterIsolatedBlocInstance(e){const t=e.constructor,s=this.isolatedBlocMap.get(t);let n=!1;if(s){const a=s.findIndex(c=>c.uid===e.uid);a!==-1&&(s.splice(a,1),n=!0),s.length===0&&this.isolatedBlocMap.delete(t)}const o=this.isolatedBlocIndex.delete(e.uid);this.uidRegistry.delete(e.uid),this.keepAliveBlocs.delete(e),n!==o&&this.warn(`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${n}, Index removal: ${o}`)}findIsolatedBlocInstance(e,t){if(!e.isolated)return;const n=this.isolatedBlocMap.get(e);return n?n.find(a=>a._id===t):void 0}findIsolatedBlocInstanceByUid(e){return this.isolatedBlocIndex.get(e)}createNewBlocInstance(e,t,s={}){const{props:n,instanceRef:o}=s,a=new e(n);return a._instanceRef=o,a.props=n||null,a._updateId(t),a._setDisposalHandler(c=>this.disposeBloc(c)),a.isIsolated?(this.registerIsolatedBlocInstance(a),a):(this.registerBlocInstance(a),a)}static get activateBloc(){return r.instance.activateBloc}static get getBloc(){return r.instance.getBloc}static get getBlocOrThrow(){return r.instance.getBlocOrThrow}static get disposeKeepAliveBlocs(){return r.instance.disposeKeepAliveBlocs}static get disposeBlocs(){return r.instance.disposeBlocs}static get getMemoryStats(){return r.instance.getMemoryStats}static get validateConsumers(){return r.instance.validateConsumers}};i(r,"enableLog",!1),i(r,"logLevel","warn"),i(r,"resetInstance",()=>{g.resetInstance()});let l=r;class I{constructor(e){i(this,"bloc");i(this,"_observers",new Set);this.bloc=e}get size(){return this._observers.size}get observers(){return this._observers}subscribe(e){return l.log("BlacObservable.subscribe: Subscribing observer.",this.bloc,e),this._observers.add(e),()=>{l.log("BlacObservable.subscribe: Unsubscribing observer.",this.bloc,e),this.unsubscribe(e)}}unsubscribe(e){this._observers.delete(e),this.size===0&&(l.log("BlacObservable.unsubscribe: No observers left.",this.bloc),this.bloc._consumers.size===0&&!this.bloc._keepAlive&&this.bloc._disposalState==="active"&&(l.log(`[${this.bloc._name}:${this.bloc._id}] No observers or consumers left. Scheduling disposal.`),this.bloc._scheduleDisposal()))}notify(e,t,s){this._observers.forEach(n=>{let o=!1;if(n.dependencyArray){const a=n.lastState,c=n.dependencyArray(e,t);if(!a)o=!0;else if(a.length!==c.length)o=!0;else for(let h=0;h<c.length;h++){const B=a[h]||[],p=c[h]||[];if(B.length!==p.length){o=!0;break}for(let f=0;f<p.length;f++)if(!Object.is(B[f],p[f])){o=!0;break}if(o)break}n.lastState=c}else o=!0;o&&n.fn(e,t,s)})}clear(){this._observers.clear()}}function y(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(d){const e=Math.random()*16|0;return(d==="x"?e:e&3|8).toString(16)})}class _{constructor(e){i(this,"uid",y());i(this,"defaultDependencySelector");i(this,"_isolated",!1);i(this,"_observer");i(this,"_id");i(this,"_instanceRef");i(this,"_keepAlive",!1);i(this,"_createdAt",Date.now());i(this,"_disposalState","active");i(this,"_state");i(this,"_oldState");i(this,"props",null);i(this,"_batchingLock",!1);i(this,"_pendingUpdates",[]);i(this,"_consumerRefs",new Map);i(this,"_validateConsumers",()=>{const e=[];for(const[t,s]of this._consumerRefs)s.deref()===void 0&&e.push(t);for(const t of e)this._consumers.delete(t),this._consumerRefs.delete(t);this._consumers.size===0&&!this._keepAlive&&this._disposalState==="active"&&this._scheduleDisposal()});i(this,"_updateId",e=>{const t=this._id;!e||e===t||(this._id=e)});i(this,"onDispose");i(this,"_consumers",new Set);i(this,"_addConsumer",(e,t)=>{var s;this._disposalState==="active"&&(this._consumers.has(e)||(this._consumers.add(e),t&&this._consumerRefs.set(e,new WeakRef(t)),(s=globalThis.Blac)==null||s.log(`[${this._name}:${this._id}] Consumer added. Total consumers: ${this._consumers.size}`)))});i(this,"_removeConsumer",e=>{var t,s;this._consumers.has(e)&&(this._consumers.delete(e),this._consumerRefs.delete(e),(t=globalThis.Blac)==null||t.log(`[${this._name}:${this._id}] Consumer removed. Remaining consumers: ${this._consumers.size}, keepAlive: ${this._keepAlive}`),this._consumers.size===0&&!this._keepAlive&&this._disposalState==="active"&&((s=globalThis.Blac)==null||s.log(`[${this._name}:${this._id}] No consumers left and not keep-alive. Scheduling disposal.`),this._scheduleDisposal()))});i(this,"_disposalHandler");i(this,"lastUpdate",Date.now());i(this,"_batchingEnabled",!1);i(this,"_pushState",(e,t,s)=>{if(e===void 0){console.warn("BlocBase._pushState: newState is undefined",this);return}if(s!==void 0&&typeof s!="object"&&typeof s!="function"){console.warn("BlocBase._pushState: Invalid action type",this,s);return}if(this._batchingEnabled){this._pendingUpdates.push({newState:e,oldState:t,action:s}),this._oldState=t,this._state=e;return}this._oldState=t,this._state=e,this._observer.notify(e,t,s),this.lastUpdate=Date.now()});i(this,"batch",e=>{if(this._batchingLock)return e();this._batchingLock=!0,this._batchingEnabled=!0,this._pendingUpdates=[];try{const t=e();if(this._pendingUpdates.length>0){const s=this._pendingUpdates[this._pendingUpdates.length-1];this._observer.notify(s.newState,s.oldState,s.action),this.lastUpdate=Date.now()}return t}finally{this._batchingEnabled=!1,this._batchingLock=!1,this._pendingUpdates=[]}});this._state=e,this._observer=new I(this),this._id=this.constructor.name;const t=this.constructor;this._keepAlive=typeof t.keepAlive=="boolean"?t.keepAlive:!1,this._isolated=typeof t.isolated=="boolean"?t.isolated:!1}get isIsolated(){return this._isolated}get isKeepAlive(){return this._keepAlive}get state(){return this._state}get _name(){return this.constructor.name}_dispose(){var e;this._disposalState==="active"&&(this._disposalState="disposing",this._consumers.clear(),this._consumerRefs.clear(),this._observer.clear(),(e=this.onDispose)==null||e.call(this),this._disposalState="disposed")}_setDisposalHandler(e){this._disposalHandler=e}_scheduleDisposal(){this._disposalState==="active"&&this._consumers.size===0&&!this._keepAlive&&(this._disposalHandler?this._disposalHandler(this):this._dispose())}}i(_,"isolated",!1),i(_,"keepAlive",!1);class b extends _{constructor(){super(...arguments);i(this,"eventHandlers",new Map);i(this,"_eventQueue",[]);i(this,"_isProcessingEvent",!1);i(this,"add",async t=>{this._eventQueue.push(t),this._isProcessingEvent||await this._processEventQueue()})}on(t,s){this.eventHandlers.has(t)&&l.warn(`[Bloc ${this._name}:${String(this._id)}] Handler for event '${t.name}' already registered. It will be overwritten.`),this.eventHandlers.set(t,s)}async _processEventQueue(){if(!this._isProcessingEvent){this._isProcessingEvent=!0;try{for(;this._eventQueue.length>0;){const t=this._eventQueue.shift();await this._processEvent(t)}}finally{this._isProcessingEvent=!1}}}async _processEvent(t){const s=t.constructor,n=this.eventHandlers.get(s);if(n){const o=a=>{const c=this.state;this._pushState(a,c,t)};try{await n(t,o)}catch(a){const c=t.constructor.name||"UnnamedConstructor",h={blocName:this._name,blocId:String(this._id),eventType:c,currentState:this.state,action:t,timestamp:new Date().toISOString()};if(l.error(`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${c}':`,a,"Context:",h),a instanceof Error&&a.name==="CriticalError")throw a}}else{const o=t.constructor.name||"UnnamedConstructor";l.warn(`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${o}'.`,"Registered handlers:",Array.from(this.eventHandlers.keys()).map(a=>a.name),"Action was:",t)}}}class w extends _{emit(e){if(Object.is(e,this.state))return;const t=this.state,s=e;this._pushState(s,t)}patch(e,t=!1){if(typeof this.state!="object"||this.state===null){l.warn("Cubit.patch: was called on a cubit where the state is not an object. This is a no-op.");return}let s=!1;if(t)s=!0;else for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const a=this.state[n];if(!Object.is(e[n],a)){s=!0;break}}s&&this.emit({...this.state,...e})}}class S{static setUp(){this.originalInstance=l.instance,l.resetInstance(),l.enableLog=!1}static tearDown(){l.resetInstance()}static createBloc(e,...t){const s=new e(...t);return l.activateBloc(s),s}static async waitForState(e,t,s=5e3){return new Promise((n,o)=>{const a=setTimeout(()=>{o(new Error(`Timeout waiting for state matching predicate after ${s}ms`))},s),c=e._observer.subscribe({id:`test-waiter-${crypto.randomUUID()}`,fn:h=>{t(h)&&(clearTimeout(a),c(),n(h))}});t(e.state)&&(clearTimeout(a),c(),n(e.state))})}static async expectStates(e,t,s=5e3){const n=[];return new Promise((o,a)=>{const c=setTimeout(()=>{a(new Error(`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(n)}`))},s),h=e._observer.subscribe({id:`test-expecter-${crypto.randomUUID()}`,fn:B=>{if(n.push(B),n.length===t.length){clearTimeout(c),h();for(let p=0;p<t.length;p++){const f=t[p],m=n[p];if(JSON.stringify(f)!==JSON.stringify(m)){a(new Error(`State mismatch at index ${p}. Expected: ${JSON.stringify(f)}, Received: ${JSON.stringify(m)}`));return}}o()}}})})}}i(S,"originalInstance");class x extends b{constructor(t){super(t);i(this,"mockHandlers",new Map)}mockEventHandler(t,s){this.on(t,s)}getHandlerCount(){return this.eventHandlers.size}hasHandler(t){return this.eventHandlers.has(t)}}class A extends w{constructor(t){super(t);i(this,"stateHistory",[]);this.stateHistory.push(t)}emit(t){this.stateHistory.push(t),super.emit(t)}getStateHistory(){return[...this.stateHistory]}clearStateHistory(){this.stateHistory=[this.state]}}class E{constructor(){i(this,"initialStats");this.initialStats=l.getMemoryStats()}checkForLeaks(){const e=l.getMemoryStats(),t=e.registeredBlocs>this.initialStats.registeredBlocs||e.isolatedBlocs>this.initialStats.isolatedBlocs||e.keepAliveBlocs>this.initialStats.keepAliveBlocs,s=`
1
+ "use strict";var U=Object.defineProperty;var H=(u,e,t)=>e in u?U(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var n=(u,e,t)=>H(u,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class R{constructor(e){n(this,"bloc");n(this,"_observers",new Set);this.bloc=e}get size(){return this._observers.size}get observers(){return this._observers}subscribe(e){const t=this.bloc._disposalState;return t===_.DISPOSED||t===_.DISPOSING?(d.log("BlacObservable.subscribe: Cannot subscribe to disposed/disposing bloc.",this.bloc,e),()=>{}):(d.log("BlacObservable.subscribe: Subscribing observer.",this.bloc,e),this._observers.add(e),t===_.DISPOSAL_REQUESTED&&(d.log("BlacObservable.subscribe: Cancelling disposal due to new subscription.",this.bloc),this.bloc._atomicStateTransition(_.DISPOSAL_REQUESTED,_.ACTIVE)),()=>{d.log("BlacObservable.subscribe: Unsubscribing observer.",this.bloc,e),this.unsubscribe(e)})}unsubscribe(e){this._observers.delete(e),this.size===0&&(d.log("BlacObservable.unsubscribe: No observers left.",this.bloc),this.bloc._consumers.size===0&&!this.bloc._keepAlive&&this.bloc._disposalState===_.ACTIVE&&(d.log(`[${this.bloc._name}:${this.bloc._id}] No observers or consumers left. Scheduling disposal.`),this.bloc._scheduleDisposal()))}notify(e,t,s){this._observers.forEach(i=>{let r=!1;if(i.dependencyArray){const a=i.lastState,o=i.dependencyArray(e,t,this.bloc);if(!a)r=!0;else if(a.length!==o.length)r=!0;else for(let l=0;l<o.length;l++)if(!Object.is(a[l],o[l])){r=!0;break}i.lastState=o}else r=!0;r&&i.fn(e,t,s)})}clear(){this._observers.clear()}}function C(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(u){const e=Math.random()*16|0;return(u==="x"?e:e&3|8).toString(16)})}var _=(u=>(u.ACTIVE="active",u.DISPOSAL_REQUESTED="disposal_requested",u.DISPOSING="disposing",u.DISPOSED="disposed",u))(_||{});class S{constructor(e){n(this,"uid",C());n(this,"defaultDependencySelector");n(this,"_isolated",!1);n(this,"_observer");n(this,"_id");n(this,"_instanceRef");n(this,"_keepAlive",!1);n(this,"_createdAt",Date.now());n(this,"_disposalState","active");n(this,"_disposalRequestTime",0);n(this,"_state");n(this,"_oldState");n(this,"props",null);n(this,"_batchingLock",!1);n(this,"_pendingUpdates",[]);n(this,"_consumerRefs",new Map);n(this,"_validateConsumers",()=>{const e=[];for(const[t,s]of this._consumerRefs)s.deref()===void 0&&e.push(t);for(const t of e)this._consumers.delete(t),this._consumerRefs.delete(t);this._consumers.size===0&&!this._keepAlive&&this._disposalState==="active"&&this._scheduleDisposal()});n(this,"_updateId",e=>{const t=this._id;!e||e===t||(this._id=e)});n(this,"onDispose");n(this,"_consumers",new Set);n(this,"_addConsumer",(e,t)=>{var s;return this._disposalState!=="active"?!1:(this._consumers.has(e)||(this._consumers.add(e),t&&this._consumerRefs.set(e,new WeakRef(t)),(s=globalThis.Blac)==null||s.log(`[${this._name}:${this._id}] Consumer added. Total consumers: ${this._consumers.size}`)),!0)});n(this,"_removeConsumer",e=>{var t,s;this._consumers.has(e)&&(this._consumers.delete(e),this._consumerRefs.delete(e),(t=globalThis.Blac)==null||t.log(`[${this._name}:${this._id}] Consumer removed. Remaining consumers: ${this._consumers.size}, keepAlive: ${this._keepAlive}`),this._consumers.size===0&&!this._keepAlive&&this._disposalState==="active"&&((s=globalThis.Blac)==null||s.log(`[${this._name}:${this._id}] No consumers left and not keep-alive. Scheduling disposal.`),this._scheduleDisposal()))});n(this,"_disposalHandler");n(this,"lastUpdate",Date.now());n(this,"_batchingEnabled",!1);n(this,"_pushState",(e,t,s)=>{if(e!==void 0&&!(s!==void 0&&typeof s!="object"&&typeof s!="function")){if(this._batchingEnabled){this._pendingUpdates.push({newState:e,oldState:t,action:s}),this._oldState=t,this._state=e;return}this._oldState=t,this._state=e,this._observer.notify(e,t,s),this.lastUpdate=Date.now()}});n(this,"batch",e=>{if(this._batchingLock)return e();this._batchingLock=!0,this._batchingEnabled=!0,this._pendingUpdates=[];try{const t=e();if(this._pendingUpdates.length>0){const s=this._pendingUpdates[this._pendingUpdates.length-1];this._observer.notify(s.newState,s.oldState,s.action),this.lastUpdate=Date.now()}return t}finally{this._batchingEnabled=!1,this._batchingLock=!1,this._pendingUpdates=[]}});this._state=e,this._observer=new R(this),this._id=this.constructor.name;const t=this.constructor;this._keepAlive=typeof t.keepAlive=="boolean"?t.keepAlive:!1,this._isolated=typeof t.isolated=="boolean"?t.isolated:!1}get isIsolated(){return this._isolated}get isKeepAlive(){return this._keepAlive}get state(){return this._disposalState==="disposed"?this._state:this._state}get isDisposed(){return this._disposalState==="disposed"}get _name(){return this.constructor.name}_atomicStateTransition(e,t){var s,i,r,a;if(this._disposalState===e){const o=this._disposalState;return this._disposalState=t,(s=globalThis.Blac)!=null&&s.enableLog&&((i=globalThis.Blac)==null||i.log(`[${this._name}:${this._id}] State transition: ${o} -> ${t} (SUCCESS)`)),{success:!0,currentState:t,previousState:o}}return(r=globalThis.Blac)!=null&&r.enableLog&&((a=globalThis.Blac)==null||a.log(`[${this._name}:${this._id}] State transition failed: expected ${e}, current ${this._disposalState}`)),{success:!1,currentState:this._disposalState,previousState:e}}_dispose(){var t;let e=this._atomicStateTransition("active","disposing");if(e.success||(e=this._atomicStateTransition("disposal_requested","disposing")),!e.success)return!1;try{return this._consumers.clear(),this._consumerRefs.clear(),this._observer.clear(),(t=this.onDispose)==null||t.call(this),this._atomicStateTransition("disposing","disposed").success}catch(s){throw this._disposalState="active",s}}_setDisposalHandler(e){this._disposalHandler=e}_scheduleDisposal(){if(!this._atomicStateTransition("active","disposal_requested").success)return;if(!(this._consumers.size===0&&!this._keepAlive)){this._atomicStateTransition("disposal_requested","active");return}this._disposalRequestTime=Date.now(),queueMicrotask(()=>{this._consumers.size===0&&!this._keepAlive&&this._observer.size===0&&this._disposalState==="disposal_requested"?this._disposalHandler?this._disposalHandler(this):this._dispose():this._atomicStateTransition("disposal_requested","active")})}}n(S,"isolated",!1),n(S,"keepAlive",!1);const I=class I{getInstance(){return I._instance||(I._instance=new d({__unsafe_ignore_singleton:!0})),I._instance}setInstance(e){I._instance=e}resetInstance(){const e=I._instance;if(I._instance=new d({__unsafe_ignore_singleton:!0}),e)for(const t of e.keepAliveBlocs)I._instance.keepAliveBlocs.add(t),I._instance.uidRegistry.set(t.uid,t)}};n(I,"_instance");let T=I,b=new T;function N(u){b=u}const c=class c{constructor(e={}){n(this,"createdAt",Date.now());n(this,"blocInstanceMap",new Map);n(this,"isolatedBlocMap",new Map);n(this,"isolatedBlocIndex",new Map);n(this,"uidRegistry",new Map);n(this,"keepAliveBlocs",new Set);n(this,"postChangesToDocument",!1);n(this,"log",(...e)=>{c.logSpy&&c.logSpy(e),c.enableLog&&c.logLevel,c.enableLog&&c.logLevel});n(this,"warn",(e,...t)=>{c.enableLog});n(this,"error",(e,...t)=>{c.enableLog});n(this,"resetInstance",()=>{this.log("Reset Blac instance");const e=new Map(this.blocInstanceMap),t=new Map(this.isolatedBlocMap);e.forEach(s=>{!s._keepAlive&&s._disposalState===_.ACTIVE&&this.disposeBloc(s)}),t.forEach(s=>{s.forEach(i=>{!i._keepAlive&&i._disposalState===_.ACTIVE&&this.disposeBloc(i)})}),this.blocInstanceMap.clear(),this.isolatedBlocMap.clear(),this.isolatedBlocIndex.clear(),b.resetInstance()});n(this,"disposeBloc",e=>{const t=e._disposalState;if(![_.ACTIVE,_.DISPOSAL_REQUESTED].includes(t)){this.log(`[${e._name}:${String(e._id)}] disposeBloc called on bloc in invalid state: ${t}`);return}const i=e.constructor,r=this.createBlocInstanceMapKey(e._name,e._id);this.log(`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(i.isolated)}`),e._dispose(),i.isolated?(this.unregisterIsolatedBlocInstance(e),this.blocInstanceMap.delete(r)):this.unregisterBlocInstance(e),this.log("dispatched bloc",e)});n(this,"activateBloc",e=>{if(e._disposalState!==_.ACTIVE){this.log(`[${e._name}:${String(e._id)}] activateBloc called on disposed bloc. Ignoring.`);return}const t=e.constructor;(e.isIsolated?this.findIsolatedBlocInstance(t,e._id):this.findRegisteredBlocInstance(t,e._id))||(this.log(`[${e._name}:${String(e._id)}] activateBloc called. Isolated: ${String(e.isIsolated)}`),e.isIsolated?this.registerIsolatedBlocInstance(e):this.registerBlocInstance(e))});n(this,"getBloc",(e,t={})=>{const{id:s,forceNewInstance:i}=t,r=e,a=s??e.name;if(this.log(`[${e.name}:${String(a)}] (getBloc) Called:`,{options:t,base:r}),!i)if(r.isolated){const l=this.findIsolatedBlocInstance(e,t.instanceRef??a);if(l)return l;if(t.throwIfNotFound)throw new Error(`Isolated bloc ${e.name} not found`)}else{const l=this.findRegisteredBlocInstance(e,a);if(l)return l;if(t.throwIfNotFound)throw new Error(`Registered bloc ${e.name} not found`)}const o=this.createNewBlocInstance(e,a,t);if(this.log(`[${e.name}:${String(a)}] (getBloc) No existing instance found. Creating new one.`,t,o),!o)throw new Error(`[getBloc] Failed to create bloc instance for ${e.name}. This should never happen.`);return o});n(this,"getBlocOrThrow",(e,t={})=>{const s=e.isolated,i=t.id||e.name,r=s?this.findIsolatedBlocInstance(e,i):this.findRegisteredBlocInstance(e,i);if(r)return r;throw new Error(`Bloc ${e.name} not found`)});n(this,"getAllBlocs",(e,t={})=>{const s=[];if(this.blocInstanceMap.forEach(i=>{i.constructor===e&&s.push(i)}),t.searchIsolated!==!1){const i=this.isolatedBlocMap.get(e);i&&s.push(...i.map(r=>r))}return s});n(this,"disposeKeepAliveBlocs",e=>{const t=[];for(const s of this.keepAliveBlocs)(!e||s.constructor===e)&&t.push(s);t.forEach(s=>s._dispose())});n(this,"disposeBlocs",e=>{const t=[];for(const s of this.blocInstanceMap.values())e(s)&&t.push(s);for(const s of this.isolatedBlocMap.values())for(const i of s)e(i)&&t.push(i);t.forEach(s=>s._dispose())});n(this,"getMemoryStats",()=>({totalBlocs:this.uidRegistry.size,registeredBlocs:this.blocInstanceMap.size,isolatedBlocs:Array.from(this.isolatedBlocMap.values()).reduce((e,t)=>e+t.length,0),keepAliveBlocs:this.keepAliveBlocs.size,isolatedBlocTypes:this.isolatedBlocMap.size}));n(this,"validateConsumers",()=>{for(const e of this.uidRegistry.values())e._validateConsumers(),e._consumers.size===0&&!e._keepAlive&&e._disposalState===_.ACTIVE&&setTimeout(()=>{e._consumers.size===0&&!e._keepAlive&&e._disposalState===_.ACTIVE&&this.disposeBloc(e)},1e3)});const{__unsafe_ignore_singleton:t=!1}=e;if(!t)return c.instance;b.setInstance(this)}static get instance(){return b.getInstance()}static get getAllBlocs(){return c.instance.getAllBlocs}static get log(){return c.instance.log}static getInstance(){return b.getInstance()}static get warn(){return c.instance.warn}static get error(){return c.instance.error}static get disposeBloc(){return c.instance.disposeBloc}createBlocInstanceMapKey(e,t){return`${e}:${String(t)}`}unregisterBlocInstance(e){const t=this.createBlocInstanceMapKey(e._name,e._id);this.blocInstanceMap.delete(t),this.uidRegistry.delete(e.uid),this.keepAliveBlocs.delete(e)}registerBlocInstance(e){const t=this.createBlocInstanceMapKey(e._name,e._id);this.blocInstanceMap.set(t,e),this.uidRegistry.set(e.uid,e),e._keepAlive&&this.keepAliveBlocs.add(e)}findRegisteredBlocInstance(e,t){if(e.isolated)return;const i=this.createBlocInstanceMapKey(e.name,t);return this.blocInstanceMap.get(i)}registerIsolatedBlocInstance(e){const t=e.constructor,s=this.isolatedBlocMap.get(t);s?s.push(e):this.isolatedBlocMap.set(t,[e]),this.isolatedBlocIndex.set(e.uid,e),this.uidRegistry.set(e.uid,e),e._keepAlive&&this.keepAliveBlocs.add(e)}unregisterIsolatedBlocInstance(e){const t=e.constructor,s=this.isolatedBlocMap.get(t);let i=!1;if(s){const a=s.findIndex(o=>o.uid===e.uid);a!==-1&&(s.splice(a,1),i=!0),s.length===0&&this.isolatedBlocMap.delete(t)}const r=this.isolatedBlocIndex.delete(e.uid);this.uidRegistry.delete(e.uid),this.keepAliveBlocs.delete(e),i!==r&&this.warn(`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${i}, Index removal: ${r}`)}findIsolatedBlocInstance(e,t){if(!e.isolated)return;const i=this.isolatedBlocMap.get(e);return i?i.find(a=>a._id===t):void 0}findIsolatedBlocInstanceByUid(e){return this.isolatedBlocIndex.get(e)}createNewBlocInstance(e,t,s={}){const{props:i,instanceRef:r}=s,a=new e(i);return a._instanceRef=r,a.props=i||null,a._updateId(t),a._setDisposalHandler(o=>this.disposeBloc(o)),a.isIsolated?(this.registerIsolatedBlocInstance(a),a):(this.registerBlocInstance(a),a)}static get activateBloc(){return c.instance.activateBloc}static get getBloc(){return c.instance.getBloc}static get getBlocOrThrow(){return c.instance.getBlocOrThrow}static get disposeKeepAliveBlocs(){return c.instance.disposeKeepAliveBlocs}static get disposeBlocs(){return c.instance.disposeBlocs}static get getMemoryStats(){return c.instance.getMemoryStats}static get validateConsumers(){return c.instance.validateConsumers}};n(c,"enableLog",!1),n(c,"logLevel","warn"),n(c,"logSpy",null),n(c,"resetInstance",()=>{b.resetInstance()});let d=c;class $ extends S{constructor(){super(...arguments);n(this,"eventHandlers",new Map);n(this,"_eventQueue",[]);n(this,"_isProcessingEvent",!1);n(this,"add",async t=>{this._eventQueue.push(t),this._isProcessingEvent||await this._processEventQueue()})}on(t,s){this.eventHandlers.has(t)&&d.warn(`[Bloc ${this._name}:${String(this._id)}] Handler for event '${t.name}' already registered. It will be overwritten.`),this.eventHandlers.set(t,s)}async _processEventQueue(){if(!this._isProcessingEvent){this._isProcessingEvent=!0;try{for(;this._eventQueue.length>0;){const t=this._eventQueue.shift();await this._processEvent(t)}}finally{this._isProcessingEvent=!1}}}async _processEvent(t){const s=t.constructor,i=this.eventHandlers.get(s);if(i){const r=a=>{const o=this.state;this._pushState(a,o,t)};try{await i(t,r)}catch(a){const o=t.constructor.name||"UnnamedConstructor",l={blocName:this._name,blocId:String(this._id),eventType:o,currentState:this.state,action:t,timestamp:new Date().toISOString()};if(d.error(`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${o}':`,a,"Context:",l),a instanceof Error&&a.name==="CriticalError")throw a}}else{const r=t.constructor.name||"UnnamedConstructor";d.warn(`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${r}'.`,"Registered handlers:",Array.from(this.eventHandlers.keys()).map(a=>a.name),"Action was:",t)}}}class P extends S{emit(e){if(Object.is(e,this.state))return;const t=this.state,s=e;this._pushState(s,t)}patch(e,t=!1){if(typeof this.state!="object"||this.state===null){d.warn("Cubit.patch: was called on a cubit where the state is not an object. This is a no-op.");return}let s=!1;if(t)s=!0;else for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const a=this.state[i];if(!Object.is(e[i],a)){s=!0;break}}s&&this.emit({...this.state,...e})}}class E{static setUp(){this.originalInstance=d.instance,d.resetInstance(),d.enableLog=!1}static tearDown(){d.resetInstance()}static createBloc(e,...t){const s=new e(...t);return d.activateBloc(s),s}static async waitForState(e,t,s=5e3){return new Promise((i,r)=>{const a=setTimeout(()=>{r(new Error(`Timeout waiting for state matching predicate after ${s}ms`))},s),o=e._observer.subscribe({id:`test-waiter-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,fn:l=>{t(l)&&(clearTimeout(a),o(),i(l))}});t(e.state)&&(clearTimeout(a),o(),i(e.state))})}static async expectStates(e,t,s=5e3){const i=[];return new Promise((r,a)=>{const o=setTimeout(()=>{a(new Error(`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(i)}`))},s),l=e._observer.subscribe({id:`test-expecter-${crypto.randomUUID()}`,fn:p=>{if(i.push(p),i.length===t.length){clearTimeout(o),l();for(let h=0;h<t.length;h++){const m=t[h],v=i[h];if(JSON.stringify(m)!==JSON.stringify(v)){a(new Error(`State mismatch at index ${h}. Expected: ${JSON.stringify(m)}, Received: ${JSON.stringify(v)}`));return}}r()}}})})}}n(E,"originalInstance");class L extends ${constructor(t){super(t);n(this,"mockHandlers",new Map)}mockEventHandler(t,s){this.on(t,s)}getHandlerCount(){return this.eventHandlers.size}hasHandler(t){return this.eventHandlers.has(t)}}class z extends P{constructor(t){super(t);n(this,"stateHistory",[]);this.stateHistory.push(t)}emit(t){this.stateHistory.push(t),super.emit(t)}getStateHistory(){return[...this.stateHistory]}clearStateHistory(){this.stateHistory=[this.state]}}class j{constructor(){n(this,"initialStats");this.initialStats=d.getMemoryStats()}checkForLeaks(){const e=d.getMemoryStats(),t=e.registeredBlocs>this.initialStats.registeredBlocs||e.isolatedBlocs>this.initialStats.isolatedBlocs||e.keepAliveBlocs>this.initialStats.keepAliveBlocs,s=`
2
2
  Memory Leak Detection Report:
3
3
  - Initial registered blocs: ${this.initialStats.registeredBlocs}
4
4
  - Current registered blocs: ${e.registeredBlocs}
@@ -7,5 +7,5 @@ Memory Leak Detection Report:
7
7
  - Initial keep-alive blocs: ${this.initialStats.keepAliveBlocs}
8
8
  - Current keep-alive blocs: ${e.keepAliveBlocs}
9
9
  - Potential leaks detected: ${t?"YES":"NO"}
10
- `.trim();return{hasLeaks:t,report:s,stats:e}}}exports.Blac=l;exports.BlacObservable=I;exports.Bloc=b;exports.BlocBase=_;exports.BlocTest=S;exports.Cubit=w;exports.MemoryLeakDetector=E;exports.MockBloc=x;exports.MockCubit=A;exports.generateUUID=y;exports.setBlacInstanceManager=M;
10
+ `.trim();return{hasLeaks:t,report:s,stats:e}}}class O{constructor(){n(this,"consumers",new WeakMap);n(this,"registrationCount",0);n(this,"activeConsumers",0)}register(e,t){this.registrationCount++,this.consumers.get(e)||this.activeConsumers++,this.consumers.set(e,{id:t,lastNotified:Date.now(),hasRendered:!1,stateAccesses:new Set,classAccesses:new Set,stateValues:new Map,classValues:new Map,accessCount:0,lastAccessTime:0,firstAccessTime:0})}unregister(e){e&&this.consumers.get(e)&&(this.consumers.delete(e),this.activeConsumers=Math.max(0,this.activeConsumers-1))}trackAccess(e,t,s,i){const r=this.consumers.get(e);if(!r)return;const a=Date.now();r.firstAccessTime||(r.firstAccessTime=a),r.accessCount++,r.lastAccessTime=a,t==="state"?(r.stateAccesses.add(s),i!==void 0&&r.stateValues.set(s,{value:i,lastAccessTime:a})):(r.classAccesses.add(s),i!==void 0&&r.classValues.set(s,{value:i,lastAccessTime:a}))}resetTracking(e){const t=this.consumers.get(e);t&&(t.stateAccesses.clear(),t.classAccesses.clear(),t.stateValues.clear(),t.classValues.clear(),t.accessCount=0,t.firstAccessTime=0)}getDependencies(e){const t=this.consumers.get(e);return t?{statePaths:Array.from(t.stateAccesses),classPaths:Array.from(t.classAccesses)}:null}hasValuesChanged(e,t,s){const i=this.consumers.get(e);if(!i)return!0;let r=!1;const a=Date.now();if(i.stateValues.size===0&&i.classValues.size===0&&(i.stateAccesses.size>0||i.classAccesses.size>0))return!0;for(const[o,l]of i.stateValues)try{const p=this.getValueAtPath(t,o);p!==l.value&&(i.stateValues.set(o,{value:p,lastAccessTime:a}),r=!0)}catch{r=!0}for(const[o,l]of i.classValues)try{const p=this.getValueAtPath(s,o);p!==l.value&&(i.classValues.set(o,{value:p,lastAccessTime:a}),r=!0)}catch{r=!0}return r}shouldNotifyConsumer(e,t){const s=this.consumers.get(e);if(!s)return!1;for(const i of t){if(s.stateAccesses.has(i)||s.classAccesses.has(i))return!0;for(const r of s.stateAccesses)if(i.startsWith(r+".")||r.startsWith(i+"."))return!0}return!1}updateLastNotified(e){const t=this.consumers.get(e);t&&(t.lastNotified=Date.now())}getConsumerInfo(e){return this.consumers.get(e)}setHasRendered(e,t){const s=this.consumers.get(e);s&&(s.hasRendered=t)}hasConsumer(e){return this.consumers.has(e)}getStats(){return{totalRegistrations:this.registrationCount,activeConsumers:this.activeConsumers}}getValueAtPath(e,t){const s=t.split(".");let i=e;for(const r of s){if(i==null)return;i=i[r]}return i}}const w=new WeakMap;let f={stateProxiesCreated:0,classProxiesCreated:0,cacheHits:0,cacheMisses:0,propertyAccesses:0,nestedProxiesCreated:0,totalProxiesCreated:0,createdAt:Date.now()};class y{static createStateProxy(e){const{target:t,consumerRef:s,consumerTracker:i,path:r=""}=e;if(!s||!i||typeof t!="object"||t===null)return t;let a=w.get(t);a||(a=new WeakMap,w.set(t,a));const o=a.get(s);if(o)return f.cacheHits++,o;f.cacheMisses++;const l={get(h,m){if(typeof m=="symbol"||m==="constructor")return Reflect.get(h,m);const v=r?`${r}.${m}`:m;f.propertyAccesses++;const g=Reflect.get(h,m),k=g&&typeof g==="object"&&g!==null?void 0:g;if(i.trackAccess(s,"state",v,k),g&&typeof g=="object"&&g!==null){const B=Object.getPrototypeOf(g)===Object.prototype,M=Array.isArray(g);if(B||M)return f.nestedProxiesCreated++,y.createStateProxy({target:g,consumerRef:s,consumerTracker:i,path:v})}return g},has(h,m){return m in h},ownKeys(h){return Reflect.ownKeys(h)},getOwnPropertyDescriptor(h,m){return Reflect.getOwnPropertyDescriptor(h,m)},set(){return!1},deleteProperty(){return!1}},p=new Proxy(t,l);return a.set(s,p),f.stateProxiesCreated++,f.totalProxiesCreated++,p}static createClassProxy(e){const{target:t,consumerRef:s,consumerTracker:i}=e;if(!s||!i)return t;let r=w.get(t);r||(r=new WeakMap,w.set(t,r));const a=r.get(s);if(a)return f.cacheHits++,a;f.cacheMisses++;const o={get(p,h){const m=Reflect.get(p,h);let v=!1,g=p;const A=new WeakSet,D=10;let k=0;for(;g&&!v&&k<D&&!A.has(g);){A.add(g);try{const x=Object.getOwnPropertyDescriptor(g,h);if(x&&x.get){v=!0;break}g=Object.getPrototypeOf(g),k++}catch{break}}if(!v)return m;f.propertyAccesses++;const B=m,V=B!==null&&typeof B!="object"?B:void 0;return i.trackAccess(s,"class",String(h),V),m},has(p,h){return h in p},ownKeys(p){return Reflect.ownKeys(p)},getOwnPropertyDescriptor(p,h){return Reflect.getOwnPropertyDescriptor(p,h)}},l=new Proxy(t,o);return r.set(s,l),f.classProxiesCreated++,f.totalProxiesCreated++,l}static getProxyState(e){return y.createStateProxy({target:e.state,consumerRef:e.consumerRef,consumerTracker:e.consumerTracker})}static getProxyBlocInstance(e){return y.createClassProxy({target:e.blocInstance,consumerRef:e.consumerRef,consumerTracker:e.consumerTracker})}static getStats(){const e=Date.now()-f.createdAt;return{...f,totalProxies:f.stateProxiesCreated+f.classProxiesCreated,cacheEfficiency:f.cacheHits+f.cacheMisses>0?`${(f.cacheHits/(f.cacheHits+f.cacheMisses)*100).toFixed(1)}%`:"N/A",lifetime:`${e}ms`,proxiesPerSecond:e>0?(f.totalProxiesCreated/(e/1e3)).toFixed(2):"N/A"}}static resetStats(){f={stateProxiesCreated:0,classProxiesCreated:0,cacheHits:0,cacheMisses:0,propertyAccesses:0,nestedProxiesCreated:0,totalProxiesCreated:0,createdAt:Date.now()}}}class K{constructor(e,t){n(this,"id",`consumer-${C()}`);n(this,"blocConstructor");n(this,"componentRef",{current:{}});n(this,"blocInstance");n(this,"consumerTracker");n(this,"unmountTime",0);n(this,"mountTime",0);n(this,"dependencyValues");n(this,"isUsingDependencies",!1);n(this,"hasMounted",!1);n(this,"mountCount",0);n(this,"options");n(this,"createStateProxy",e=>y.createStateProxy({target:e.target,consumerRef:this.componentRef.current,consumerTracker:this}));n(this,"createClassProxy",e=>y.createClassProxy({target:e.target,consumerRef:this.componentRef.current,consumerTracker:this}));n(this,"createSubscription",e=>this.blocInstance._observer.subscribe({id:this.id,fn:(s,i)=>{var r;if(this.isUsingDependencies&&((r=this.options)!=null&&r.dependencies)){const a=this.options.dependencies(this.blocInstance);if(!this.hasDependencyValuesChanged(this.dependencyValues,a))return;this.dependencyValues=a}else{const a=this.consumerTracker.getConsumerInfo(this.componentRef.current);if(a&&a.hasRendered&&!this.consumerTracker.hasValuesChanged(this.componentRef.current,s,this.blocInstance))return}e.onChange()}}));n(this,"mount",()=>{var e,t;if(this.isUsingDependencies&&((e=this.options)!=null&&e.dependencies)&&(this.dependencyValues=this.options.dependencies(this.blocInstance)),this.mountCount++,this.blocInstance._addConsumer(this.id,this.componentRef.current),!this.hasMounted&&(this.hasMounted=!0,this.mountTime=Date.now(),(t=this.options)!=null&&t.onMount))try{this.options.onMount(this.blocInstance)}catch(s){throw s}});n(this,"unmount",()=>{var e;if(this.unmountTime=Date.now(),this.consumerTracker.unregister(this.componentRef.current),this.blocInstance._removeConsumer(this.id),(e=this.options)!=null&&e.onUnmount)try{this.options.onUnmount(this.blocInstance)}catch{}});n(this,"getProxyState",e=>this.isUsingDependencies?e:y.getProxyState({state:e,consumerRef:this.componentRef.current,consumerTracker:this}));n(this,"getProxyBlocInstance",()=>this.isUsingDependencies?this.blocInstance:y.getProxyBlocInstance({blocInstance:this.blocInstance,consumerRef:this.componentRef.current,consumerTracker:this}));this.options=t,this.blocConstructor=e.blocConstructor,this.componentRef=e.componentRef,this.isUsingDependencies=!!(t!=null&&t.dependencies),this.consumerTracker=new O,this.blocInstance=this.updateBlocInstance(),this.consumerTracker.register(e.componentRef.current,this.id),this.isUsingDependencies&&(t!=null&&t.dependencies)&&(this.dependencyValues=t.dependencies(this.blocInstance))}trackAccess(e,t,s,i){this.consumerTracker.trackAccess(e,t,s,i)}getConsumerDependencies(e){return this.consumerTracker.getDependencies(e)}shouldNotifyConsumer(e,t){const s=this.consumerTracker.getConsumerInfo(e);return!s||!s.hasRendered?!0:this.consumerTracker.shouldNotifyConsumer(e,t)}updateLastNotified(e){this.consumerTracker.updateLastNotified(e),this.consumerTracker.setHasRendered(e,!0)}resetConsumerTracking(){this.consumerTracker.resetTracking(this.componentRef.current)}updateBlocInstance(){var e,t;return this.blocInstance=d.instance.getBloc(this.blocConstructor,{props:(e=this.options)==null?void 0:e.props,id:(t=this.options)==null?void 0:t.id,instanceRef:this.id}),this.blocInstance}get calledOnMount(){return this.hasMounted}hasDependencyValuesChanged(e,t){if(!e||e.length!==t.length)return!0;for(let s=0;s<e.length;s++)if(!Object.is(e[s],t[s]))return!0;return!1}}exports.Blac=d;exports.BlacAdapter=K;exports.BlacObservable=R;exports.Bloc=$;exports.BlocBase=S;exports.BlocLifecycleState=_;exports.BlocTest=E;exports.ConsumerTracker=O;exports.Cubit=P;exports.MemoryLeakDetector=j;exports.MockBloc=L;exports.MockCubit=z;exports.ProxyFactory=y;exports.generateUUID=C;exports.setBlacInstanceManager=N;
11
11
  //# sourceMappingURL=index.cjs.js.map