@directive-run/lit 1.1.0 → 1.1.2

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 CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var $=Symbol("directive"),r=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},d=class extends r{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),process.env.NODE_ENV!=="production"&&!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},h=class extends r{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),process.env.NODE_ENV!=="production"&&(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},y=class extends r{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=adapterUtils.computeInspectState(t);}subscribe(){this.value=adapterUtils.computeInspectState(this.system);let e=()=>{this.value=adapterUtils.computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=adapterUtils.createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},v=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},p=class extends r{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=adapterUtils.defaultEquality,o){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=o?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let a=this.runWithTracking();this.value=a.value,this.trackedFactKeys=a.factKeys,this.trackedDeriveKeys=a.deriveKeys;}runWithTracking(){return adapterUtils.runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&adapterUtils.depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},m=class extends r{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},g=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},f=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},R=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
1
+ 'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var B=Symbol("directive"),r=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},h=class extends r{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},y=class extends r{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},v=class extends r{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=adapterUtils.computeInspectState(t);}subscribe(){this.value=adapterUtils.computeInspectState(this.system);let e=()=>{this.value=adapterUtils.computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=adapterUtils.createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},p=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},m=class extends r{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=adapterUtils.defaultEquality,o){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=o?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let a=this.runWithTracking();this.value=a.value,this.trackedFactKeys=a.factKeys,this.trackedDeriveKeys=a.deriveKeys;}runWithTracking(){return adapterUtils.runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&adapterUtils.depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},g=class extends r{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},f=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},b=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},k=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
2
2
  1. Accessed before hostConnected (e.g., in a class field initializer)
3
3
  2. Accessed after hostDisconnected (system was destroyed)
4
- Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?core.createSystem({module:this.options}):core.createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},b=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let o=core.createRequirementStatusPlugin();this.statusPlugin=o,e.push(o.plugin);}let t=core.createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let o={};for(let a of i)o[a]=t.read(a);return o};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function q(s,e,t){return new d(s,e,t)}function _(s,e,t){return new h(s,e,t)}function O(s,e,t){return new y(s,e,t)}function A(s,e,t){return new v(s,e,t)}function P(s,e,t,i){return new m(s,e,t,i)}function B(s,e,t,i=adapterUtils.defaultEquality,n){return new p(s,e,t,i,n)}function N(s,e,t){return new g(s,e,t)}function z(s,e,t){return new f(s,e,t)}function W(s,e,t,i){return new S(s,e,t,i)}function j(s,e,t){return new b(s,e,t)}function L(s){return adapterUtils.assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function G(s){return adapterUtils.assertSystem("useEvents",s),s.events}var k=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=adapterUtils.buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=adapterUtils.buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function J(s){return adapterUtils.assertSystem("useHistory",s),adapterUtils.buildHistoryState(s)}function Q(s,e){return ()=>s.read(e)}function X(s,e){return ()=>s.facts.$store.get(e)}function Y(){return {createDerived:(s,e,t)=>q(s,e,t),createFact:(s,e,t)=>_(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>P(s,e,t,i)}}var M=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function Z(s,e,t,i){return new M(s,e,t,i)}var D=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},T=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=adapterUtils.mergeHydrationFacts(this.snapshot,t?.initialFacts),n=core.createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}};Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.ConstraintStatusController=f;exports.DerivedController=d;exports.DirectiveSelectorController=p;exports.ExplainController=g;exports.FactController=h;exports.HistoryController=k;exports.HydrationController=T;exports.InspectController=y;exports.ModuleController=b;exports.NamespacedSelectorController=M;exports.OptimisticUpdateController=S;exports.QuerySystemController=D;exports.RequirementStatusController=v;exports.SystemController=R;exports.WatchController=m;exports.createConstraintStatus=z;exports.createDerived=q;exports.createDirectiveSelector=B;exports.createExplain=N;exports.createFact=_;exports.createInspect=O;exports.createModule=j;exports.createNamespacedSelector=Z;exports.createOptimisticUpdate=W;exports.createRequirementStatus=A;exports.createTypedHooks=Y;exports.createWatch=P;exports.directiveContext=$;exports.getDerived=Q;exports.getFact=X;exports.useDispatch=L;exports.useEvents=G;exports.useHistory=J;//# sourceMappingURL=index.cjs.map
4
+ Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?core.createSystem({module:this.options}):core.createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let o=core.createRequirementStatusPlugin();this.statusPlugin=o,e.push(o.plugin);}let t=core.createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let o={};for(let a of i)o[a]=t.read(a);return o};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function P(s,e,t){return new h(s,e,t)}function _(s,e,t){return new y(s,e,t)}function z(s,e,t){return new v(s,e,t)}function N(s,e,t){return new p(s,e,t)}function U(s,e,t,i){return new g(s,e,t,i)}function W(s,e,t,i=adapterUtils.defaultEquality,n){return new m(s,e,t,i,n)}function j(s,e,t){return new f(s,e,t)}function L(s,e,t){return new S(s,e,t)}function G(s,e,t,i){return new b(s,e,t,i)}function J(s,e,t){return new M(s,e,t)}function Q(s){return adapterUtils.assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function X(s){return adapterUtils.assertSystem("useEvents",s),s.events}var T=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=adapterUtils.buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=adapterUtils.buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function Y(s){return adapterUtils.assertSystem("useHistory",s),adapterUtils.buildHistoryState(s)}function Z(s,e){return ()=>s.read(e)}function ee(s,e){return ()=>s.facts.$store.get(e)}function te(){return {createDerived:(s,e,t)=>P(s,e,t),createFact:(s,e,t)=>_(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>U(s,e,t,i)}}var C=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function se(s,e,t,i){return new C(s,e,t,i)}var D=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},x=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=adapterUtils.mergeHydrationFacts(this.snapshot,t?.initialFacts),n=core.createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}};Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.ConstraintStatusController=S;exports.DerivedController=h;exports.DirectiveSelectorController=m;exports.ExplainController=f;exports.FactController=y;exports.HistoryController=T;exports.HydrationController=x;exports.InspectController=v;exports.ModuleController=M;exports.NamespacedSelectorController=C;exports.OptimisticUpdateController=b;exports.QuerySystemController=D;exports.RequirementStatusController=p;exports.SystemController=k;exports.WatchController=g;exports.createConstraintStatus=L;exports.createDerived=P;exports.createDirectiveSelector=W;exports.createExplain=j;exports.createFact=_;exports.createInspect=z;exports.createModule=J;exports.createNamespacedSelector=se;exports.createOptimisticUpdate=G;exports.createRequirementStatus=N;exports.createTypedHooks=te;exports.createWatch=U;exports.directiveContext=B;exports.getDerived=Z;exports.getFact=ee;exports.useDispatch=Q;exports.useEvents=X;exports.useHistory=Y;//# sourceMappingURL=index.cjs.map
5
5
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"+GAmEO,IAAMA,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,EAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,CAAAA,CAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OA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AWA,CAAAA,CAChB7E,CAAAA,CAAK,aAAA,CAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CAAC,CAEvB,gBAAA,EAAyB,CACvB,IAAA,IAAWC,KAAU,IAAA,CAAK,OAAA,CACxBA,CAAAA,CAAO,OAAA,EAAQ,CAEjB,IAAA,CAAK,QAAU,GACjB,CAEA,YAAA,CACEyC,CAAAA,CACAC,EAUuB,CACvB,IAAMmC,CAAAA,CAAcC,gCAAAA,CAAoB,IAAA,CAAK,QAAA,CAAUpC,GAAQ,YAAY,CAAA,CAErE1C,CAAAA,CAASuC,iBAAAA,CAAa,CAC1B,MAAA,CAAQE,EACR,OAAA,CAASC,CAAAA,EAAQ,OAAA,CACjB,KAAA,CAAOA,CAAAA,EAAQ,KAAA,CACf,cAAeA,CAAAA,EAAQ,aAAA,CACvB,OAAQA,CAAAA,EAAQ,MAAA,CAChB,WAAYA,CAAAA,EAAQ,UAAA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK7E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.cjs","sourcesContent":["/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n TraceOption,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n HistoryState,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (process.env.NODE_ENV !== \"production\") {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (process.env.NODE_ENV !== \"production\") {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\n\n /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<T extends { start: () => void; destroy: () => void; isRunning?: boolean; [key: string]: any }>\n implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(host: ReactiveControllerHost, snapshot?: Record<string, unknown>) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(this.snapshot, config?.initialFacts);\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","dev_true_default","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"+GAoEO,IAAMA,CAAAA,CAAmB,OAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,CAAAA,CAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,OAASC,CAAAA,CACdD,CAAAA,CAAK,aAAA,CAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,KAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,KAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,C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EvB,gBAAA,EAAyB,CACvB,IAAA,IAAWC,KAAU,IAAA,CAAK,OAAA,CACxBA,CAAAA,CAAO,OAAA,EAAQ,CAEjB,IAAA,CAAK,QAAU,GACjB,CAEA,YAAA,CACE0C,CAAAA,CACAC,EAUuB,CACvB,IAAMmC,CAAAA,CAAcC,gCAAAA,CAAoB,IAAA,CAAK,QAAA,CAAUpC,GAAQ,YAAY,CAAA,CAErE3C,CAAAA,CAASwC,iBAAAA,CAAa,CAC1B,MAAA,CAAQE,EACR,OAAA,CAASC,CAAAA,EAAQ,OAAA,CACjB,KAAA,CAAOA,CAAAA,EAAQ,KAAA,CACf,cAAeA,CAAAA,EAAQ,aAAA,CACvB,OAAQA,CAAAA,EAAQ,MAAA,CAChB,WAAYA,CAAAA,EAAQ,UAAA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK9E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.cjs","sourcesContent":["/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n TraceOption,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n HistoryState,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\n\n /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<T extends { start: () => void; destroy: () => void; isRunning?: boolean; [key: string]: any }>\n implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(host: ReactiveControllerHost, snapshot?: Record<string, unknown>) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(this.snapshot, config?.initialFacts);\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {defaultEquality,computeInspectState,createThrottle,runTrackedSelector,assertSystem,buildHistoryState,mergeHydrationFacts,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';var $=Symbol("directive"),r=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},d=class extends r{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),process.env.NODE_ENV!=="production"&&!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},h=class extends r{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),process.env.NODE_ENV!=="production"&&(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},y=class extends r{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=computeInspectState(t);}subscribe(){this.value=computeInspectState(this.system);let e=()=>{this.value=computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},v=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},p=class extends r{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=defaultEquality,o){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=o?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let a=this.runWithTracking();this.value=a.value,this.trackedFactKeys=a.factKeys,this.trackedDeriveKeys=a.deriveKeys;}runWithTracking(){return runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},m=class extends r{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},g=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},f=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},R=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
1
+ import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {defaultEquality,computeInspectState,createThrottle,runTrackedSelector,assertSystem,buildHistoryState,mergeHydrationFacts,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';var B=Symbol("directive"),r=class{host;system;unsubscribe;constructor(e,t){this.host=e,this.system=t,e.addController(this);}hostConnected(){this.subscribe();}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}requestUpdate(){this.host.requestUpdate();}},h=class extends r{keys;isMulti;value;constructor(e,t,i){super(e,t),this.isMulti=Array.isArray(i),this.keys=this.isMulti?i:[i],this.value=this.getValues(),!this.isMulti&&this.value===void 0&&console.warn(`[Directive] DerivedController("${this.keys[0]}") returned undefined. Check that "${this.keys[0]}" is defined in your module's derive property.`);}getValues(){if(this.isMulti){let e={};for(let t of this.keys)e[t]=this.system.read(t);return e}return this.system.read(this.keys[0])}subscribe(){this.value=this.getValues(),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.getValues(),this.requestUpdate();});}},y=class extends r{factKey;value;constructor(e,t,i){super(e,t),this.factKey=i,this.value=t.facts.$store.get(i),(t.facts.$store.has(i)||console.warn(`[Directive] FactController("${i}") \u2014 fact not found in store. Check that "${i}" is defined in your module's schema.`));}subscribe(){this.value=this.system.facts.$store.get(this.factKey),this.unsubscribe=this.system.facts.$store.subscribe([this.factKey],()=>{this.value=this.system.facts.$store.get(this.factKey),this.requestUpdate();});}},v=class extends r{value;throttleMs;throttleCleanup;unsubSettled;constructor(e,t,i){super(e,t),this.throttleMs=i?.throttleMs??0,this.value=computeInspectState(t);}subscribe(){this.value=computeInspectState(this.system);let e=()=>{this.value=computeInspectState(this.system),this.requestUpdate();};if(this.throttleMs>0){let{throttled:t,cleanup:i}=createThrottle(e,this.throttleMs);this.throttleCleanup=i,this.unsubscribe=this.system.facts.$store.subscribeAll(t),this.unsubSettled=this.system.onSettledChange(t);}else this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.throttleCleanup?.(),this.unsubSettled?.(),super.hostDisconnected();}},p=class{host;statusPlugin;type;unsubscribe;value;constructor(e,t,i){this.host=e,this.statusPlugin=t,this.type=i,this.value=t.getStatus(i),e.addController(this);}hostConnected(){this.value=this.statusPlugin.getStatus(this.type),this.unsubscribe=this.statusPlugin.subscribe(()=>{this.value=this.statusPlugin.getStatus(this.type),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}},m=class extends r{selector;equalityFn;autoTrack;deriveKeySet;trackedFactKeys=[];trackedDeriveKeys=[];unsubs=[];value;constructor(e,t,i,n=defaultEquality,o){super(e,t),this.selector=i,this.equalityFn=n,this.autoTrack=o?.autoTrack??true,this.deriveKeySet=new Set(Object.keys(t.derive??{}));let a=this.runWithTracking();this.value=a.value,this.trackedFactKeys=a.factKeys,this.trackedDeriveKeys=a.deriveKeys;}runWithTracking(){return runTrackedSelector(this.system,this.deriveKeySet,this.selector)}resubscribe(){for(let t of this.unsubs)t();this.unsubs=[];let e=()=>{let t=this.runWithTracking();this.equalityFn(this.value,t.value)||(this.value=t.value,this.requestUpdate()),this.autoTrack&&depsChanged(this.trackedFactKeys,t.factKeys,this.trackedDeriveKeys,t.deriveKeys)&&(this.trackedFactKeys=t.factKeys,this.trackedDeriveKeys=t.deriveKeys,this.resubscribe());};this.autoTrack?(this.trackedFactKeys.length>0?this.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys,e)):this.trackedDeriveKeys.length===0&&this.unsubs.push(this.system.facts.$store.subscribeAll(e)),this.trackedDeriveKeys.length>0&&this.unsubs.push(this.system.subscribe(this.trackedDeriveKeys,e))):this.unsubs.push(this.system.facts.$store.subscribeAll(e));}subscribe(){let e=this.runWithTracking();this.value=e.value,this.trackedFactKeys=e.factKeys,this.trackedDeriveKeys=e.deriveKeys,this.resubscribe();}hostDisconnected(){for(let e of this.unsubs)e();this.unsubs=[],super.hostDisconnected();}},g=class extends r{key;callback;constructor(e,t,i,n){super(e,t),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},f=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},S=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},b=class{host;system;statusPlugin;requirementType;snapshot=null;statusUnsub=null;isPending=false;error=null;constructor(e,t,i,n){this.host=e,this.system=t,this.statusPlugin=i,this.requirementType=n,e.addController(this);}hostConnected(){}hostDisconnected(){this.statusUnsub?.(),this.statusUnsub=null;}rollback(){this.snapshot&&(this.system.restore(this.snapshot),this.snapshot=null),this.isPending=false,this.error=null,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate();}mutate(e){this.snapshot=this.system.getSnapshot(),this.isPending=true,this.error=null,this.system.batch(e),this.host.requestUpdate(),this.statusPlugin&&this.requirementType&&(this.statusUnsub?.(),this.statusUnsub=this.statusPlugin.subscribe(()=>{let t=this.statusPlugin.getStatus(this.requirementType);!t.isLoading&&!t.hasError?(this.snapshot=null,this.isPending=false,this.statusUnsub?.(),this.statusUnsub=null,this.host.requestUpdate()):t.hasError&&(this.error=t.lastError,this.rollback());}));}},k=class{options;_system=null;constructor(e,t){this.options=t,e.addController(this);}get system(){if(!this._system)throw new Error(`[Directive] SystemController.system is not available. This can happen if:
2
2
  1. Accessed before hostConnected (e.g., in a class field initializer)
3
3
  2. Accessed after hostDisconnected (system was destroyed)
4
- Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?createSystem({module:this.options}):createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},b=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let o=createRequirementStatusPlugin();this.statusPlugin=o,e.push(o.plugin);}let t=createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let o={};for(let a of i)o[a]=t.read(a);return o};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function q(s,e,t){return new d(s,e,t)}function _(s,e,t){return new h(s,e,t)}function O(s,e,t){return new y(s,e,t)}function A(s,e,t){return new v(s,e,t)}function P(s,e,t,i){return new m(s,e,t,i)}function B(s,e,t,i=defaultEquality,n){return new p(s,e,t,i,n)}function N(s,e,t){return new g(s,e,t)}function z(s,e,t){return new f(s,e,t)}function W(s,e,t,i){return new S(s,e,t,i)}function j(s,e,t){return new b(s,e,t)}function L(s){return assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function G(s){return assertSystem("useEvents",s),s.events}var k=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function J(s){return assertSystem("useHistory",s),buildHistoryState(s)}function Q(s,e){return ()=>s.read(e)}function X(s,e){return ()=>s.facts.$store.get(e)}function Y(){return {createDerived:(s,e,t)=>q(s,e,t),createFact:(s,e,t)=>_(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>P(s,e,t,i)}}var M=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function Z(s,e,t,i){return new M(s,e,t,i)}var D=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},T=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=mergeHydrationFacts(this.snapshot,t?.initialFacts),n=createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}};export{f as ConstraintStatusController,d as DerivedController,p as DirectiveSelectorController,g as ExplainController,h as FactController,k as HistoryController,T as HydrationController,y as InspectController,b as ModuleController,M as NamespacedSelectorController,S as OptimisticUpdateController,D as QuerySystemController,v as RequirementStatusController,R as SystemController,m as WatchController,z as createConstraintStatus,q as createDerived,B as createDirectiveSelector,N as createExplain,_ as createFact,O as createInspect,j as createModule,Z as createNamespacedSelector,W as createOptimisticUpdate,A as createRequirementStatus,Y as createTypedHooks,P as createWatch,$ as directiveContext,Q as getDerived,X as getFact,L as useDispatch,G as useEvents,J as useHistory};//# sourceMappingURL=index.js.map
4
+ Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?createSystem({module:this.options}):createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},M=class{host;moduleDef;config;_system=null;unsubFacts;unsubDerived;facts={};derived={};statusPlugin;get system(){if(!this._system)throw new Error("[Directive] ModuleController.system is not available before hostConnected.");return this._system}get events(){return this.system.events}constructor(e,t,i){this.host=e,this.moduleDef=t,this.config=i,e.addController(this);}hostConnected(){let e=[...this.config?.plugins??[]];if(this.config?.status){let o=createRequirementStatusPlugin();this.statusPlugin=o,e.push(o.plugin);}let t=createSystem({module:this.moduleDef,plugins:e.length>0?e:void 0,trace:this.config?.trace,errorBoundary:this.config?.errorBoundary,tickMs:this.config?.tickMs,zeroConfig:this.config?.zeroConfig,initialFacts:this.config?.initialFacts});this._system=t,t.start(),this.facts=t.facts.$store.toObject(),this.unsubFacts=t.facts.$store.subscribeAll(()=>{this.facts=t.facts.$store.toObject(),this.host.requestUpdate();});let i=Object.keys(t.derive??{}),n=()=>{let o={};for(let a of i)o[a]=t.read(a);return o};this.derived=n(),i.length>0&&(this.unsubDerived=t.subscribe(i,()=>{this.derived=n(),this.host.requestUpdate();}));}hostDisconnected(){this.unsubFacts?.(),this.unsubDerived?.(),this._system?.destroy(),this._system=null;}dispatch(e){this.system.dispatch(e);}};function P(s,e,t){return new h(s,e,t)}function _(s,e,t){return new y(s,e,t)}function z(s,e,t){return new v(s,e,t)}function N(s,e,t){return new p(s,e,t)}function U(s,e,t,i){return new g(s,e,t,i)}function W(s,e,t,i=defaultEquality,n){return new m(s,e,t,i,n)}function j(s,e,t){return new f(s,e,t)}function L(s,e,t){return new S(s,e,t)}function G(s,e,t,i){return new b(s,e,t,i)}function J(s,e,t){return new M(s,e,t)}function Q(s){return assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function X(s){return assertSystem("useEvents",s),s.events}var T=class{constructor(e,t){this._host=e;this._system=t;this._host.addController(this);}value=null;_unsub;hostConnected(){this.value=buildHistoryState(this._system),this._unsub=this._system.onHistoryChange(()=>{this.value=buildHistoryState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function Y(s){return assertSystem("useHistory",s),buildHistoryState(s)}function Z(s,e){return ()=>s.read(e)}function ee(s,e){return ()=>s.facts.$store.get(e)}function te(){return {createDerived:(s,e,t)=>P(s,e,t),createFact:(s,e,t)=>_(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>U(s,e,t,i)}}var C=class{host;system;keys;selector;unsubscribe;value;constructor(e,t,i,n){this.host=e,this.system=t,this.keys=i,this.selector=n,this.value=n(t),e.addController(this);}hostConnected(){this.value=this.selector(this.system),this.unsubscribe=this.system.subscribe(this.keys,()=>{this.value=this.selector(this.system),this.host.requestUpdate();});}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0;}};function se(s,e,t,i){return new C(s,e,t,i)}var D=class{_system=null;factory;constructor(e,t){this.factory=t,e.addController(this);}get system(){if(!this._system)throw new Error("[Directive] QuerySystemController.system is not available. Access it only in lifecycle methods or after the element is connected.");return this._system}hostConnected(){this._system=this.factory(),this._system.isRunning||this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},x=class{snapshot;systems=[];constructor(e,t){this.snapshot=t,e.addController(this);}hostConnected(){}hostDisconnected(){for(let e of this.systems)e.destroy();this.systems=[];}createSystem(e,t){let i=mergeHydrationFacts(this.snapshot,t?.initialFacts),n=createSystem({module:e,plugins:t?.plugins,trace:t?.trace,errorBoundary:t?.errorBoundary,tickMs:t?.tickMs,zeroConfig:t?.zeroConfig,initialFacts:i});return this.systems.push(n),typeof window<"u"&&n.start(),n}};export{S as ConstraintStatusController,h as DerivedController,m as DirectiveSelectorController,f as ExplainController,y as FactController,T as HistoryController,x as HydrationController,v as InspectController,M as ModuleController,C as NamespacedSelectorController,b as OptimisticUpdateController,D as QuerySystemController,p as RequirementStatusController,k as SystemController,g as WatchController,L as createConstraintStatus,P as createDerived,W as createDirectiveSelector,j as createExplain,_ as createFact,z as createInspect,J as createModule,se as createNamespacedSelector,G as createOptimisticUpdate,N as createRequirementStatus,te as createTypedHooks,U as createWatch,B as directiveContext,Z as getDerived,ee as getFact,Q as useDispatch,X as useEvents,Y as useHistory};//# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"8TAmEO,IAAMA,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,EAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,CAAAA,CAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,cAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,IAAA,CAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACEC,EAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,QAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA,CAAO,IAAA,CAAK,OAAA,CAAWA,EAAmB,CAACA,CAAa,CAAA,CAC7D,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,SAAA,EAAU,CAExB,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,YAAA,EACvB,CAAC,IAAA,CAAK,OAAA,EAAW,IAAA,CAAK,QAAU,MAAA,EAClC,OAAA,CAAQ,IAAA,CACN,CAAA,+BAAA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AAA,CACf,cAAeA,CAAAA,EAAQ,aAAA,CACvB,OAAQA,CAAAA,EAAQ,MAAA,CAChB,WAAYA,CAAAA,EAAQ,UAAA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK7E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.js","sourcesContent":["/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n TraceOption,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n HistoryState,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (process.env.NODE_ENV !== \"production\") {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (process.env.NODE_ENV !== \"production\") {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\n\n /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<T extends { start: () => void; destroy: () => void; isRunning?: boolean; [key: string]: any }>\n implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(host: ReactiveControllerHost, snapshot?: Record<string, unknown>) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(this.snapshot, config?.initialFacts);\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","dev_true_default","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","HistoryController","_host","_system","buildHistoryState","useHistory","getFact","createTypedHooks","NamespacedSelectorController","keys","createNamespacedSelector","QuerySystemController","factory","HydrationController","snapshot","mergedFacts","mergeHydrationFacts"],"mappings":"8TAoEO,IAAMA,CAAAA,CAAmB,OAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACrD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,CAAAA,CAAiC,CACzE,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,OAASC,CAAAA,CACdD,CAAAA,CAAK,aAAA,CAAc,IAAI,EACzB,CAEA,aAAA,EAAsB,CACpB,KAAK,SAAA,GACP,CAEA,gBAAA,EAAyB,CACvB,IAAA,CAAK,WAAA,IAAc,CACnB,KAAK,WAAA,CAAc,OACrB,CAIU,aAAA,EAAsB,CAC9B,IAAA,CAAK,IAAA,CAAK,aAAA,GACZ,CACF,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACpD,IAAA,CACA,QACR,KAAA,CAEA,WAAA,CACEC,CAAAA,CAEAC,CAAAA,CACAE,CAAAA,CACA,CACA,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,OAAA,CAAU,KAAA,CAAM,OAAA,CAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,KAAO,IAAA,CAAK,OAAA,CAAWA,CAAAA,CAAmB,CAACA,CAAa,CAAA,CAC7D,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,SAAA,EAAU,CAGtB,CAAC,IAAA,CAAK,OAAA,EAAW,IAAA,CAAK,QAAU,MAAA,EAClC,OAAA,CAAQ,IAAA,CACN,CAAA,+BAAA,EAAkC,IAAA,CAAK,IAAA,CAA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AA,CACpB,YAAA,CAAcmC,CAChB,CAAQ,CAAA,CAER,YAAK,OAAA,CAAQ,IAAA,CAAK9E,CAAM,CAAA,CAEpB,OAAO,MAAA,CAAW,KACpBA,CAAAA,CAAO,KAAA,EAAM,CAGRA,CACT,CACF","file":"index.js","sourcesContent":["/**\n * Lit Adapter - Consolidated Web Components integration for Directive\n *\n * Controllers: DerivedController, FactController,\n * InspectController (with throttle), RequirementStatusController,\n * DirectiveSelectorController,\n * WatchController (with fact mode), SystemController,\n * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController\n *\n * Factories: createDerived, createFact, createInspect,\n * createRequirementStatus, createWatch,\n * createDirectiveSelector, useDispatch, useEvents, useHistory,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type {\n CreateSystemOptionsSingle,\n TraceOption,\n ErrorBoundaryConfig,\n InferDerivations,\n InferEvents,\n InferFacts,\n ModuleDef,\n ModuleSchema,\n ModulesMap,\n NamespacedSystem,\n Plugin,\n SingleModuleSystem,\n SystemSnapshot,\n HistoryState,\n} from \"@directive-run/core\";\nimport {\n createRequirementStatusPlugin,\n createSystem,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n type ConstraintInfo,\n type InspectState,\n type TrackedSelectorResult,\n assertSystem,\n buildHistoryState,\n computeInspectState,\n createThrottle,\n defaultEquality,\n depsChanged,\n mergeHydrationFacts,\n runTrackedSelector,\n shallowEqual,\n} from \"@directive-run/core/adapter-utils\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport isDevelopment from \"#is-development\";\n\n// Re-export for convenience\nexport type { RequirementTypeStatus, InspectState, ConstraintInfo };\nexport { shallowEqual };\n\n/** Type for the requirement status plugin return value */\nexport type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Context key for Directive system.\n * Use with @lit/context for dependency injection across shadow DOM boundaries.\n */\nexport const directiveContext = Symbol(\"directive\");\n\n// ============================================================================\n// Base Controller\n// ============================================================================\n\n/**\n * Base controller that manages system subscription lifecycle.\n */\nabstract class DirectiveController implements ReactiveController {\n protected host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n protected system: SingleModuleSystem<any>;\n protected unsubscribe?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n this.host = host;\n this.system = system;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.subscribe();\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n protected abstract subscribe(): void;\n\n protected requestUpdate(): void {\n this.host.requestUpdate();\n }\n}\n\n// ============================================================================\n// Core Controllers\n// ============================================================================\n\n/**\n * Reactive controller for derivations.\n * Accepts a single key (string) or an array of keys (string[]).\n * - Single key: `.value` returns `T`\n * - Array of keys: `.value` returns `Record<string, unknown>`\n */\nexport class DerivedController<T> extends DirectiveController {\n private keys: string[];\n private isMulti: boolean;\n value: T;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n ) {\n super(host, system);\n this.isMulti = Array.isArray(key);\n this.keys = this.isMulti ? (key as string[]) : [key as string];\n this.value = this.getValues();\n\n if (isDevelopment) {\n if (!this.isMulti && this.value === undefined) {\n console.warn(\n `[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n `Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n );\n }\n }\n }\n\n private getValues(): T {\n if (this.isMulti) {\n const result: Record<string, unknown> = {};\n for (const id of this.keys) {\n result[id] = this.system.read(id);\n }\n return result as T;\n }\n return this.system.read(this.keys[0]!) as T;\n }\n\n protected subscribe(): void {\n this.value = this.getValues();\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.getValues();\n this.requestUpdate();\n });\n }\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n private factKey: string;\n value: T | undefined;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n ) {\n super(host, system);\n this.factKey = factKey;\n this.value = system.facts.$store.get(factKey) as T | undefined;\n\n if (isDevelopment) {\n if (!system.facts.$store.has(factKey)) {\n console.warn(\n `[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n `Check that \"${factKey}\" is defined in your module's schema.`,\n );\n }\n }\n }\n\n protected subscribe(): void {\n this.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n this.unsubscribe = this.system.facts.$store.subscribe(\n [this.factKey],\n () => {\n this.value = this.system.facts.$store.get(this.factKey) as\n | T\n | undefined;\n this.requestUpdate();\n },\n );\n }\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n value: InspectState;\n private throttleMs: number;\n private throttleCleanup?: () => void;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n ) {\n super(host, system);\n this.throttleMs = options?.throttleMs ?? 0;\n this.value = computeInspectState(system);\n }\n\n protected subscribe(): void {\n this.value = computeInspectState(this.system);\n\n const update = () => {\n this.value = computeInspectState(this.system);\n this.requestUpdate();\n };\n\n if (this.throttleMs > 0) {\n const { throttled, cleanup } = createThrottle(update, this.throttleMs);\n this.throttleCleanup = cleanup;\n this.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n this.unsubSettled = this.system.onSettledChange(throttled);\n } else {\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n }\n\n hostDisconnected(): void {\n this.throttleCleanup?.();\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n private host: ReactiveControllerHost;\n private statusPlugin: StatusPlugin;\n private type: string;\n private unsubscribe?: () => void;\n value: RequirementTypeStatus;\n\n constructor(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n ) {\n this.host = host;\n this.statusPlugin = statusPlugin;\n this.type = type;\n this.value = statusPlugin.getStatus(type);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.statusPlugin.getStatus(this.type);\n this.unsubscribe = this.statusPlugin.subscribe(() => {\n this.value = this.statusPlugin.getStatus(this.type);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\n// ============================================================================\n// Selector Controllers\n// ============================================================================\n\n/**\n * Reactive controller for selecting across all facts.\n * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.\n */\nexport class DirectiveSelectorController<R> extends DirectiveController {\n private selector: (state: Record<string, unknown>) => R;\n private equalityFn: (a: R, b: R) => boolean;\n private autoTrack: boolean;\n private deriveKeySet: Set<string>;\n private trackedFactKeys: string[] = [];\n private trackedDeriveKeys: string[] = [];\n private unsubs: Array<() => void> = [];\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n ) {\n super(host, system);\n this.selector = selector;\n this.equalityFn = equalityFn;\n this.autoTrack = options?.autoTrack ?? true;\n this.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n const initial = this.runWithTracking();\n this.value = initial.value;\n this.trackedFactKeys = initial.factKeys;\n this.trackedDeriveKeys = initial.deriveKeys;\n }\n\n private runWithTracking(): TrackedSelectorResult<R> {\n return runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n }\n\n private resubscribe(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n\n const onUpdate = () => {\n const result = this.runWithTracking();\n if (!this.equalityFn(this.value, result.value)) {\n this.value = result.value;\n this.requestUpdate();\n }\n if (this.autoTrack) {\n // Re-track: check if deps changed\n if (\n depsChanged(\n this.trackedFactKeys,\n result.factKeys,\n this.trackedDeriveKeys,\n result.deriveKeys,\n )\n ) {\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n }\n };\n\n if (this.autoTrack) {\n if (this.trackedFactKeys.length > 0) {\n this.unsubs.push(\n this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate),\n );\n } else if (this.trackedDeriveKeys.length === 0) {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n if (this.trackedDeriveKeys.length > 0) {\n this.unsubs.push(\n this.system.subscribe(this.trackedDeriveKeys, onUpdate),\n );\n }\n } else {\n this.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n }\n }\n\n protected subscribe(): void {\n const result = this.runWithTracking();\n this.value = result.value;\n this.trackedFactKeys = result.factKeys;\n this.trackedDeriveKeys = result.deriveKeys;\n this.resubscribe();\n }\n\n hostDisconnected(): void {\n for (const unsub of this.unsubs) unsub();\n this.unsubs = [];\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller that watches a fact or derivation and calls a callback on change.\n * The key is auto-detected — works with both fact keys and derivation keys.\n */\nexport class WatchController<T> extends DirectiveController {\n private key: string;\n private callback: (newValue: T, previousValue: T | undefined) => void;\n\n /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n ) {\n super(host, system);\n this.key = key;\n this.callback = callback;\n }\n\n protected subscribe(): void {\n this.unsubscribe = this.system.watch<T>(this.key, this.callback);\n }\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n private requirementId: string;\n value: string | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n requirementId: string,\n ) {\n super(host, system);\n this.requirementId = requirementId;\n this.value = system.explain(requirementId);\n }\n\n protected subscribe(): void {\n this.value = this.system.explain(this.requirementId);\n\n const update = () => {\n this.value = this.system.explain(this.requirementId);\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n private constraintId?: string;\n value: ConstraintInfo[] | ConstraintInfo | null;\n private unsubSettled?: () => void;\n\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n constructor(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<any>,\n constraintId?: string,\n ) {\n super(host, system);\n this.constraintId = constraintId;\n this.value = this.getVal();\n }\n\n private getVal(): ConstraintInfo[] | ConstraintInfo | null {\n const inspection = this.system.inspect();\n if (!this.constraintId) return inspection.constraints;\n return (\n inspection.constraints.find(\n (c: ConstraintInfo) => c.id === this.constraintId,\n ) ?? null\n );\n }\n\n protected subscribe(): void {\n this.value = this.getVal();\n\n const update = () => {\n this.value = this.getVal();\n this.requestUpdate();\n };\n\n this.unsubscribe = this.system.facts.$store.subscribeAll(update);\n this.unsubSettled = this.system.onSettledChange(update);\n }\n\n hostDisconnected(): void {\n this.unsubSettled?.();\n super.hostDisconnected();\n }\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n private host: ReactiveControllerHost;\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private system: SingleModuleSystem<any>;\n private statusPlugin?: StatusPlugin;\n private requirementType?: string;\n private snapshot: SystemSnapshot | null = null;\n private statusUnsub: (() => void) | null = null;\n\n isPending = false;\n error: Error | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n ) {\n this.host = host;\n this.system = system;\n this.statusPlugin = statusPlugin;\n this.requirementType = requirementType;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n this.statusUnsub?.();\n this.statusUnsub = null;\n }\n\n rollback(): void {\n if (this.snapshot) {\n this.system.restore(this.snapshot);\n this.snapshot = null;\n }\n this.isPending = false;\n this.error = null;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n }\n\n mutate(updateFn: () => void): void {\n this.snapshot = this.system.getSnapshot();\n this.isPending = true;\n this.error = null;\n this.system.batch(updateFn);\n this.host.requestUpdate();\n\n if (this.statusPlugin && this.requirementType) {\n this.statusUnsub?.();\n this.statusUnsub = this.statusPlugin.subscribe(() => {\n const status = this.statusPlugin!.getStatus(this.requirementType!);\n if (!status.isLoading && !status.hasError) {\n this.snapshot = null;\n this.isPending = false;\n this.statusUnsub?.();\n this.statusUnsub = null;\n this.host.requestUpdate();\n } else if (status.hasError) {\n this.error = status.lastError;\n this.rollback();\n }\n });\n }\n }\n}\n\n/**\n * Reactive controller that creates and manages a Directive system.\n * The system is automatically started when the host connects and destroyed when it disconnects.\n */\nexport class SystemController<M extends ModuleSchema>\n implements ReactiveController\n{\n private options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n private _system: SingleModuleSystem<M> | null = null;\n\n constructor(\n host: ReactiveControllerHost,\n options: ModuleDef<M> | CreateSystemOptionsSingle<M>,\n ) {\n this.options = options;\n host.addController(this);\n }\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] SystemController.system is not available. \" +\n \"This can happen if:\\n\" +\n \" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n \" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n \"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n \"or after the element is connected to the DOM.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n const isModule = \"id\" in this.options && \"schema\" in this.options;\n const system = isModule\n ? createSystem({ module: this.options as ModuleDef<M> })\n : createSystem(this.options as CreateSystemOptionsSingle<M>);\n this._system = system as unknown as SingleModuleSystem<M>;\n this._system.start();\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n/**\n * Module controller — zero-config all-in-one.\n * Creates system, starts it, subscribes to all facts/derivations.\n */\nexport class ModuleController<M extends ModuleSchema>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private moduleDef: ModuleDef<M>;\n private config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n };\n\n private _system: SingleModuleSystem<M> | null = null;\n private unsubFacts?: () => void;\n private unsubDerived?: () => void;\n\n facts: InferFacts<M> = {} as InferFacts<M>;\n derived: InferDerivations<M> = {} as InferDerivations<M>;\n statusPlugin?: StatusPlugin;\n\n get system(): SingleModuleSystem<M> {\n if (!this._system) {\n throw new Error(\n \"[Directive] ModuleController.system is not available before hostConnected.\",\n );\n }\n return this._system;\n }\n\n get events(): SingleModuleSystem<M>[\"events\"] {\n return this.system.events;\n }\n\n constructor(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n ) {\n this.host = host;\n this.moduleDef = moduleDef;\n this.config = config;\n host.addController(this);\n }\n\n hostConnected(): void {\n const allPlugins = [...(this.config?.plugins ?? [])];\n\n if (this.config?.status) {\n const sp = createRequirementStatusPlugin();\n this.statusPlugin = sp;\n // biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n allPlugins.push(sp.plugin as Plugin<any>);\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: this.moduleDef,\n plugins: allPlugins.length > 0 ? allPlugins : undefined,\n trace: this.config?.trace,\n errorBoundary: this.config?.errorBoundary,\n tickMs: this.config?.tickMs,\n zeroConfig: this.config?.zeroConfig,\n initialFacts: this.config?.initialFacts,\n } as any) as unknown as SingleModuleSystem<M>;\n\n this._system = system;\n system.start();\n\n // Subscribe to all facts\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.unsubFacts = system.facts.$store.subscribeAll(() => {\n this.facts = system.facts.$store.toObject() as InferFacts<M>;\n this.host.requestUpdate();\n });\n\n // Subscribe to all derivations\n const derivationKeys = Object.keys(system.derive ?? {});\n const getDerived = (): InferDerivations<M> => {\n const result: Record<string, unknown> = {};\n for (const key of derivationKeys) {\n result[key] = system.read(key);\n }\n return result as InferDerivations<M>;\n };\n this.derived = getDerived();\n\n if (derivationKeys.length > 0) {\n this.unsubDerived = system.subscribe(derivationKeys, () => {\n this.derived = getDerived();\n this.host.requestUpdate();\n });\n }\n }\n\n hostDisconnected(): void {\n this.unsubFacts?.();\n this.unsubDerived?.();\n this._system?.destroy();\n this._system = null;\n }\n\n dispatch(event: InferEvents<M>): void {\n this.system.dispatch(event);\n }\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n key: string | string[],\n): DerivedController<T> {\n return new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): FactController<T> {\n return new FactController<T>(host, system, factKey);\n}\n\n/**\n * Create an inspect controller.\n * Returns InspectState; pass `{ throttleMs }` for throttled updates.\n */\nexport function createInspect(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n options?: { throttleMs?: number },\n): InspectController {\n return new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n host: ReactiveControllerHost,\n statusPlugin: StatusPlugin,\n type: string,\n): RequirementStatusController {\n return new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n callback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n return new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n selector: (state: Record<string, unknown>) => R,\n equalityFn: (a: R, b: R) => boolean = defaultEquality,\n options?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n return new DirectiveSelectorController<R>(\n host,\n system,\n selector,\n equalityFn,\n options,\n );\n}\n\nexport function createExplain(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n requirementId: string,\n): ExplainController {\n return new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n constraintId?: string,\n): ConstraintStatusController {\n return new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n statusPlugin?: StatusPlugin,\n requirementType?: string,\n): OptimisticUpdateController {\n return new OptimisticUpdateController(\n host,\n system,\n statusPlugin,\n requirementType,\n );\n}\n\nexport function createModule<M extends ModuleSchema>(\n host: ReactiveControllerHost,\n moduleDef: ModuleDef<M>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n status?: boolean;\n },\n): ModuleController<M> {\n return new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n assertSystem(\"useDispatch\", system);\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n system: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n assertSystem(\"useEvents\", system);\n return system.events;\n}\n\n/**\n * Reactive controller for history state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private _history = new HistoryController(this, system);\n * render() {\n * const h = this._history.value;\n * return html`<button ?disabled=${!h?.canGoBack} @click=${() => h?.goBack()}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class HistoryController implements ReactiveController {\n value: HistoryState | null = null;\n private _unsub?: () => void;\n\n constructor(\n private _host: ReactiveControllerHost,\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: SingleModuleSystem<any>,\n ) {\n this._host.addController(this);\n }\n\n hostConnected(): void {\n this.value = buildHistoryState(this._system);\n this._unsub = this._system.onHistoryChange(() => {\n this.value = buildHistoryState(this._system);\n this._host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this._unsub?.();\n this._unsub = undefined;\n }\n}\n\n/**\n * Functional helper for history state (non-reactive, snapshot).\n * For reactive updates, use HistoryController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useHistory(\n system: SingleModuleSystem<any>,\n): HistoryState | null {\n assertSystem(\"useHistory\", system);\n return buildHistoryState(system);\n}\n\nexport function getDerived<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n derivationId: string,\n): () => T {\n return () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n system: SingleModuleSystem<any>,\n factKey: string,\n): () => T | undefined {\n return () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) => DerivedController<InferDerivations<M>[K]>;\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => FactController<InferFacts<M>[K]>;\n useDispatch: (\n system: SingleModuleSystem<M>,\n ) => (event: InferEvents<M>) => void;\n useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => WatchController<unknown>;\n} {\n return {\n createDerived: <K extends keyof InferDerivations<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n derivationId: K,\n ) =>\n createDerived<InferDerivations<M>[K]>(\n host,\n system,\n derivationId as string,\n ),\n createFact: <K extends keyof InferFacts<M>>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n factKey: K,\n ) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n useDispatch: (system: SingleModuleSystem<M>) => {\n return (event: InferEvents<M>) => {\n system.dispatch(event);\n };\n },\n useEvents: (system: SingleModuleSystem<M>) => system.events,\n createWatch: <K extends string>(\n host: ReactiveControllerHost,\n system: SingleModuleSystem<M>,\n key: K,\n callback: (newValue: unknown, previousValue: unknown) => void,\n ) => createWatch<unknown>(host, system, key, callback),\n };\n}\n\n// ============================================================================\n// NamespacedSelectorController — select from a NamespacedSystem\n// ============================================================================\n\n/**\n * Reactive controller that selects from a NamespacedSystem.\n * Subscribes to specified keys and triggers host updates.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private token = new NamespacedSelectorController(\n * this, system, [\"auth.token\"], (s) => s.facts.auth.token,\n * );\n * render() {\n * return html`<span>${this.token.value}</span>`;\n * }\n * }\n * ```\n */\nexport class NamespacedSelectorController<Modules extends ModulesMap, R>\n implements ReactiveController\n{\n private host: ReactiveControllerHost;\n private system: NamespacedSystem<Modules>;\n private keys: string[];\n private selector: (system: NamespacedSystem<Modules>) => R;\n private unsubscribe?: () => void;\n value: R;\n\n constructor(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n ) {\n this.host = host;\n this.system = system;\n this.keys = keys;\n this.selector = selector;\n this.value = selector(system);\n host.addController(this);\n }\n\n hostConnected(): void {\n this.value = this.selector(this.system);\n this.unsubscribe = this.system.subscribe(this.keys, () => {\n this.value = this.selector(this.system);\n this.host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n}\n\nexport function createNamespacedSelector<Modules extends ModulesMap, R>(\n host: ReactiveControllerHost,\n system: NamespacedSystem<Modules>,\n keys: string[],\n selector: (system: NamespacedSystem<Modules>) => R,\n): NamespacedSelectorController<Modules, R> {\n return new NamespacedSelectorController(host, system, keys, selector);\n}\n\n// ============================================================================\n// QuerySystemController — Stable query system with Lit lifecycle\n// ============================================================================\n\n/**\n * Lit reactive controller that creates and manages a query system.\n * Starts on connect, destroys on disconnect.\n *\n * @example\n * ```typescript\n * import { LitElement, html } from \"lit\";\n * import { QuerySystemController } from \"@directive-run/lit\";\n * import { createQuerySystem } from \"@directive-run/query\";\n *\n * class MyApp extends LitElement {\n * private app = new QuerySystemController(this, () =>\n * createQuerySystem({\n * facts: { userId: \"\" },\n * queries: { user: { key: ..., fetcher: ... } },\n * autoStart: false,\n * })\n * );\n *\n * render() {\n * const user = this.app.system.read(\"user\");\n * return html`<div>${user.data?.name}</div>`;\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: Factory return type varies\nexport class QuerySystemController<T extends { start: () => void; destroy: () => void; isRunning?: boolean; [key: string]: any }>\n implements ReactiveController\n{\n // biome-ignore lint/suspicious/noExplicitAny: System type varies\n private _system: T | null = null;\n private factory: () => T;\n\n constructor(host: ReactiveControllerHost, factory: () => T) {\n this.factory = factory;\n host.addController(this);\n }\n\n get system(): T {\n if (!this._system) {\n throw new Error(\n \"[Directive] QuerySystemController.system is not available. \" +\n \"Access it only in lifecycle methods or after the element is connected.\",\n );\n }\n return this._system;\n }\n\n hostConnected(): void {\n this._system = this.factory();\n if (!this._system.isRunning) {\n this._system.start();\n }\n }\n\n hostDisconnected(): void {\n this._system?.destroy();\n this._system = null;\n }\n}\n\n// ============================================================================\n// SSR Hydration\n// ============================================================================\n\n/**\n * Lit reactive controller for SSR hydration.\n * Accepts a DistributableSnapshot and creates a hydrated system.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private hydration = new HydrationController(this, serverSnapshot);\n * private system = this.hydration.createSystem(myModule);\n * }\n * ```\n */\nexport class HydrationController implements ReactiveController {\n private snapshot: Record<string, unknown> | undefined;\n // biome-ignore lint/suspicious/noExplicitAny: Systems vary by module schema\n private systems: SingleModuleSystem<any>[] = [];\n\n constructor(host: ReactiveControllerHost, snapshot?: Record<string, unknown>) {\n this.snapshot = snapshot;\n host.addController(this);\n }\n\n hostConnected(): void {}\n\n hostDisconnected(): void {\n for (const system of this.systems) {\n system.destroy();\n }\n this.systems = [];\n }\n\n createSystem<S extends ModuleSchema>(\n moduleDef: ModuleDef<S>,\n config?: {\n // biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n plugins?: Plugin<any>[];\n trace?: TraceOption;\n errorBoundary?: ErrorBoundaryConfig;\n tickMs?: number;\n zeroConfig?: boolean;\n // biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n initialFacts?: Record<string, any>;\n },\n ): SingleModuleSystem<S> {\n const mergedFacts = mergeHydrationFacts(this.snapshot, config?.initialFacts);\n // biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n const system = createSystem({\n module: moduleDef,\n plugins: config?.plugins,\n trace: config?.trace,\n errorBoundary: config?.errorBoundary,\n tickMs: config?.tickMs,\n zeroConfig: config?.zeroConfig,\n initialFacts: mergedFacts,\n } as any) as unknown as SingleModuleSystem<S>;\n\n this.systems.push(system);\n\n if (typeof window !== \"undefined\") {\n system.start();\n }\n\n return system;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@directive-run/lit",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
+ "imports": {
5
+ "#is-development": {
6
+ "production": "./src/dev-false.ts",
7
+ "default": "./src/dev-true.ts"
8
+ }
9
+ },
4
10
  "description": "Lit web components adapter for Directive.",
5
11
  "license": "(MIT OR Apache-2.0)",
6
12
  "author": "Jason Comes",
@@ -52,7 +58,7 @@
52
58
  "lit": "^3.1.0",
53
59
  "tsup": "^8.3.5",
54
60
  "typescript": "^5.7.2",
55
- "@directive-run/core": "1.1.0"
61
+ "@directive-run/core": "1.1.2"
56
62
  },
57
63
  "scripts": {
58
64
  "build": "tsup",