@directive-run/lit 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Comes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @directive-run/lit
2
+
3
+ Lit web components adapter for Directive. Provides reactive controllers and factory functions for reading facts, derivations, and dispatching events.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @directive-run/core @directive-run/lit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { LitElement, html } from "lit";
15
+ import { FactController, DerivedController, useEvents } from "@directive-run/lit";
16
+
17
+ class MyCounter extends LitElement {
18
+ private count = new FactController<number>(this, system, "count");
19
+ private doubled = new DerivedController<number>(this, system, "doubled");
20
+ private events = useEvents(system);
21
+
22
+ render() {
23
+ return html`
24
+ <p>Count: ${this.count.value} (doubled: ${this.doubled.value})</p>
25
+ <button @click=${() => this.events.increment()}>+</button>
26
+ `;
27
+ }
28
+ }
29
+ ```
30
+
31
+ ## Exports
32
+
33
+ **Controllers:** `FactController`, `DerivedController`, `InspectController`, `RequirementStatusController`, `DirectiveSelectorController`, `WatchController`, `ExplainController`, `ConstraintStatusController`, `OptimisticUpdateController`, `SystemController`, `ModuleController`, `TimeTravelController`
34
+
35
+ **Factories:** `createFact`, `createDerived`, `createInspect`, `createRequirementStatus`, `createWatch`, `createDirectiveSelector`, `createExplain`, `createConstraintStatus`, `createOptimisticUpdate`, `createModule`, `useDispatch`, `useEvents`, `useTimeTravel`, `getDerived`, `getFact`, `createTypedHooks`, `shallowEqual`
36
+
37
+ ## Peer Dependencies
38
+
39
+ - `lit >= 3`
40
+ - `@directive-run/core`
41
+
42
+ ## License
43
+
44
+ MIT
45
+
46
+ [Full documentation](https://directive.run/docs)
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var E=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();});}},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();}},y=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();}},g=class extends r{key;callback;constructor(e,t,i,n){super(e,t),typeof i=="string"?this.key=i:this.key=i.factKey,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();}},m=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());}));}},C=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
+ 1. Accessed before hostConnected (e.g., in a class field initializer)
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;}},S=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,debug:this.config?.debug,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 I(s,e,t){return new d(s,e,t)}function w(s,e,t){return new h(s,e,t)}function U(s,e,t){return new v(s,e,t)}function _(s,e,t){return new y(s,e,t)}function H(s,e,t,i){return new g(s,e,t,i)}function V(s,e,t,i=adapterUtils.defaultEquality,n){return new p(s,e,t,i,n)}function $(s,e,t){return new f(s,e,t)}function A(s,e,t){return new m(s,e,t)}function B(s,e,t,i){return new b(s,e,t,i)}function O(s,e,t){return new S(s,e,t)}function W(s){return adapterUtils.assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function z(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.buildTimeTravelState(this._system),this._unsub=this._system.onTimeTravelChange(()=>{this.value=adapterUtils.buildTimeTravelState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function j(s){return adapterUtils.assertSystem("useTimeTravel",s),adapterUtils.buildTimeTravelState(s)}function N(s,e){return ()=>s.read(e)}function L(s,e){return ()=>s.facts.$store.get(e)}function G(){return {createDerived:(s,e,t)=>I(s,e,t),createFact:(s,e,t)=>w(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>H(s,e,t,i)}}Object.defineProperty(exports,"shallowEqual",{enumerable:true,get:function(){return adapterUtils.shallowEqual}});exports.ConstraintStatusController=m;exports.DerivedController=d;exports.DirectiveSelectorController=p;exports.ExplainController=f;exports.FactController=h;exports.InspectController=v;exports.ModuleController=S;exports.OptimisticUpdateController=b;exports.RequirementStatusController=y;exports.SystemController=C;exports.TimeTravelController=k;exports.WatchController=g;exports.createConstraintStatus=A;exports.createDerived=I;exports.createDirectiveSelector=V;exports.createExplain=$;exports.createFact=w;exports.createInspect=U;exports.createModule=O;exports.createOptimisticUpdate=B;exports.createRequirementStatus=_;exports.createTypedHooks=G;exports.createWatch=H;exports.directiveContext=E;exports.getDerived=N;exports.getFact=L;exports.useDispatch=W;exports.useEvents=z;exports.useTimeTravel=j;//# sourceMappingURL=index.cjs.map
5
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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","keyOrOptions","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","TimeTravelController","_host","_system","buildTimeTravelState","useTimeTravel","getFact","createTypedHooks"],"mappings":"+GAgEO,IAAMA,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACtD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA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,CAAAA,EAA0B,CACjCjD,EAAO,QAAA,CAASiD,CAAK,EACtB,CAAA,CAED,UAAYjD,CAAAA,EAAkCA,CAAAA,CAAO,MAAA,CACrD,WAAA,CAAa,CACZD,CAAAA,CACAC,CAAAA,CACAE,CAAAA,CACA0B,CAAAA,GACI0B,EAAqBvD,CAAAA,CAAMC,CAAAA,CAAQE,CAAAA,CAAK0B,CAAQ,CACtD,CACD","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, useTimeTravel,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport type {\n\tCreateSystemOptionsSingle,\n\tModuleSchema,\n\tModuleDef,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferEvents,\n\tSingleModuleSystem,\n\tSystemSnapshot,\n\tTimeTravelState,\n} from \"@directive-run/core\";\nimport {\n\tcreateSystem,\n\tcreateRequirementStatusPlugin,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n\ttype InspectState,\n\ttype ConstraintInfo,\n\ttype TrackedSelectorResult,\n\tcomputeInspectState,\n\tcreateThrottle,\n\tassertSystem,\n\tdefaultEquality,\n\tbuildTimeTravelState,\n\trunTrackedSelector,\n\tdepsChanged,\n\tshallowEqual,\n} from \"@directive-run/core/adapter-utils\";\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\tprotected host: ReactiveControllerHost;\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tprotected system: SingleModuleSystem<any>;\n\tprotected unsubscribe?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n\t\tthis.host = host;\n\t\tthis.system = system;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.subscribe();\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t}\n\n\tprotected abstract subscribe(): void;\n\n\tprotected requestUpdate(): void {\n\t\tthis.host.requestUpdate();\n\t}\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\tprivate keys: string[];\n\tprivate isMulti: boolean;\n\tvalue: T;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkey: string | string[],\n\t) {\n\t\tsuper(host, system);\n\t\tthis.isMulti = Array.isArray(key);\n\t\tthis.keys = this.isMulti ? (key as string[]) : [key as string];\n\t\tthis.value = this.getValues();\n\n\t\tif (process.env.NODE_ENV !== \"production\") {\n\t\t\tif (!this.isMulti && this.value === undefined) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n\t\t\t\t\t`Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getValues(): T {\n\t\tif (this.isMulti) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const id of this.keys) {\n\t\t\t\tresult[id] = this.system.read(id);\n\t\t\t}\n\t\t\treturn result as T;\n\t\t}\n\t\treturn this.system.read(this.keys[0]!) as T;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.getValues();\n\t\tthis.unsubscribe = this.system.subscribe(this.keys, () => {\n\t\t\tthis.value = this.getValues();\n\t\t\tthis.requestUpdate();\n\t\t});\n\t}\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n\tprivate factKey: string;\n\tvalue: T | undefined;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tfactKey: string,\n\t) {\n\t\tsuper(host, system);\n\t\tthis.factKey = factKey;\n\t\tthis.value = system.facts.$store.get(factKey) as T | undefined;\n\n\t\tif (process.env.NODE_ENV !== \"production\") {\n\t\t\tif (!system.facts.$store.has(factKey)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n\t\t\t\t\t`Check that \"${factKey}\" is defined in your module's schema.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n\t\tthis.unsubscribe = this.system.facts.$store.subscribe(\n\t\t\t[this.factKey],\n\t\t\t() => {\n\t\t\t\tthis.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n\t\t\t\tthis.requestUpdate();\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n\tvalue: InspectState;\n\tprivate throttleMs: number;\n\tprivate throttleCleanup?: () => void;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: { throttleMs?: number }) {\n\t\tsuper(host, system);\n\t\tthis.throttleMs = options?.throttleMs ?? 0;\n\t\tthis.value = computeInspectState(system);\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = computeInspectState(this.system);\n\n\t\tconst update = () => {\n\t\t\tthis.value = computeInspectState(this.system);\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tif (this.throttleMs > 0) {\n\t\t\tconst { throttled, cleanup } = createThrottle(update, this.throttleMs);\n\t\t\tthis.throttleCleanup = cleanup;\n\t\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n\t\t\tthis.unsubSettled = this.system.onSettledChange(throttled);\n\t\t} else {\n\t\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t\t}\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.throttleCleanup?.();\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\tprivate statusPlugin: StatusPlugin;\n\tprivate type: string;\n\tprivate unsubscribe?: () => void;\n\tvalue: RequirementTypeStatus;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\tstatusPlugin: StatusPlugin,\n\t\ttype: string,\n\t) {\n\t\tthis.host = host;\n\t\tthis.statusPlugin = statusPlugin;\n\t\tthis.type = type;\n\t\tthis.value = statusPlugin.getStatus(type);\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.value = this.statusPlugin.getStatus(this.type);\n\t\tthis.unsubscribe = this.statusPlugin.subscribe(() => {\n\t\t\tthis.value = this.statusPlugin.getStatus(this.type);\n\t\t\tthis.host.requestUpdate();\n\t\t});\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t}\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\tprivate selector: (state: Record<string, unknown>) => R;\n\tprivate equalityFn: (a: R, b: R) => boolean;\n\tprivate autoTrack: boolean;\n\tprivate deriveKeySet: Set<string>;\n\tprivate trackedFactKeys: string[] = [];\n\tprivate trackedDeriveKeys: string[] = [];\n\tprivate unsubs: Array<() => void> = [];\n\tvalue: R;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tselector: (state: Record<string, unknown>) => R,\n\t\tequalityFn: (a: R, b: R) => boolean = defaultEquality,\n\t\toptions?: { autoTrack?: boolean },\n\t) {\n\t\tsuper(host, system);\n\t\tthis.selector = selector;\n\t\tthis.equalityFn = equalityFn;\n\t\tthis.autoTrack = options?.autoTrack ?? true;\n\t\tthis.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\t\tconst initial = this.runWithTracking();\n\t\tthis.value = initial.value;\n\t\tthis.trackedFactKeys = initial.factKeys;\n\t\tthis.trackedDeriveKeys = initial.deriveKeys;\n\t}\n\n\tprivate runWithTracking(): TrackedSelectorResult<R> {\n\t\treturn runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n\t}\n\n\tprivate resubscribe(): void {\n\t\tfor (const unsub of this.unsubs) unsub();\n\t\tthis.unsubs = [];\n\n\t\tconst onUpdate = () => {\n\t\t\tconst result = this.runWithTracking();\n\t\t\tif (!this.equalityFn(this.value, result.value)) {\n\t\t\t\tthis.value = result.value;\n\t\t\t\tthis.requestUpdate();\n\t\t\t}\n\t\t\tif (this.autoTrack) {\n\t\t\t\t// Re-track: check if deps changed\n\t\t\t\tif (depsChanged(this.trackedFactKeys, result.factKeys, this.trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\t\tthis.trackedFactKeys = result.factKeys;\n\t\t\t\t\tthis.trackedDeriveKeys = result.deriveKeys;\n\t\t\t\t\tthis.resubscribe();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tif (this.autoTrack) {\n\t\t\tif (this.trackedFactKeys.length > 0) {\n\t\t\t\tthis.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate));\n\t\t\t} else if (this.trackedDeriveKeys.length === 0) {\n\t\t\t\tthis.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n\t\t\t}\n\t\t\tif (this.trackedDeriveKeys.length > 0) {\n\t\t\t\tthis.unsubs.push(this.system.subscribe(this.trackedDeriveKeys, onUpdate));\n\t\t\t}\n\t\t} else {\n\t\t\tthis.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n\t\t}\n\t}\n\n\tprotected subscribe(): void {\n\t\tconst result = this.runWithTracking();\n\t\tthis.value = result.value;\n\t\tthis.trackedFactKeys = result.factKeys;\n\t\tthis.trackedDeriveKeys = result.deriveKeys;\n\t\tthis.resubscribe();\n\t}\n\n\thostDisconnected(): void {\n\t\tfor (const unsub of this.unsubs) unsub();\n\t\tthis.unsubs = [];\n\t\tsuper.hostDisconnected();\n\t}\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\tprivate key: string;\n\tprivate callback: (newValue: T, previousValue: T | undefined) => void;\n\n\t/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkey: string,\n\t\tcallback: (newValue: T, previousValue: T | undefined) => void,\n\t);\n\t/**\n\t * Watch a fact by explicit options.\n\t * @deprecated Use `new WatchController(host, system, factKey, callback)` instead — facts are now auto-detected.\n\t */\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\toptions: { kind: \"fact\"; factKey: string },\n\t\tcallback: (newValue: T, previousValue: T | undefined) => void,\n\t);\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkeyOrOptions: string | { kind: \"fact\"; factKey: string },\n\t\tcallback?: (newValue: T, previousValue: T | undefined) => void,\n\t) {\n\t\tsuper(host, system);\n\t\tif (typeof keyOrOptions === \"string\") {\n\t\t\tthis.key = keyOrOptions;\n\t\t} else {\n\t\t\tthis.key = keyOrOptions.factKey;\n\t\t}\n\t\tthis.callback = callback!;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.unsubscribe = this.system.watch<T>(this.key, this.callback);\n\t}\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n\tprivate requirementId: string;\n\tvalue: string | null;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string) {\n\t\tsuper(host, system);\n\t\tthis.requirementId = requirementId;\n\t\tthis.value = system.explain(requirementId);\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.system.explain(this.requirementId);\n\n\t\tconst update = () => {\n\t\t\tthis.value = this.system.explain(this.requirementId);\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n\tprivate constraintId?: string;\n\tvalue: ConstraintInfo[] | ConstraintInfo | null;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string) {\n\t\tsuper(host, system);\n\t\tthis.constraintId = constraintId;\n\t\tthis.value = this.getVal();\n\t}\n\n\tprivate getVal(): ConstraintInfo[] | ConstraintInfo | null {\n\t\tconst inspection = this.system.inspect();\n\t\tif (!this.constraintId) return inspection.constraints;\n\t\treturn inspection.constraints.find((c: ConstraintInfo) => c.id === this.constraintId) ?? null;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.getVal();\n\n\t\tconst update = () => {\n\t\t\tthis.value = this.getVal();\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tprivate system: SingleModuleSystem<any>;\n\tprivate statusPlugin?: StatusPlugin;\n\tprivate requirementType?: string;\n\tprivate snapshot: SystemSnapshot | null = null;\n\tprivate statusUnsub: (() => void) | null = null;\n\n\tisPending = false;\n\terror: Error | null = null;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tstatusPlugin?: StatusPlugin,\n\t\trequirementType?: string,\n\t) {\n\t\tthis.host = host;\n\t\tthis.system = system;\n\t\tthis.statusPlugin = statusPlugin;\n\t\tthis.requirementType = requirementType;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {}\n\n\thostDisconnected(): void {\n\t\tthis.statusUnsub?.();\n\t\tthis.statusUnsub = null;\n\t}\n\n\trollback(): void {\n\t\tif (this.snapshot) {\n\t\t\tthis.system.restore(this.snapshot);\n\t\t\tthis.snapshot = null;\n\t\t}\n\t\tthis.isPending = false;\n\t\tthis.error = null;\n\t\tthis.statusUnsub?.();\n\t\tthis.statusUnsub = null;\n\t\tthis.host.requestUpdate();\n\t}\n\n\tmutate(updateFn: () => void): void {\n\t\tthis.snapshot = this.system.getSnapshot();\n\t\tthis.isPending = true;\n\t\tthis.error = null;\n\t\tthis.system.batch(updateFn);\n\t\tthis.host.requestUpdate();\n\n\t\tif (this.statusPlugin && this.requirementType) {\n\t\t\tthis.statusUnsub?.();\n\t\t\tthis.statusUnsub = this.statusPlugin.subscribe(() => {\n\t\t\t\tconst status = this.statusPlugin!.getStatus(this.requirementType!);\n\t\t\t\tif (!status.isLoading && !status.hasError) {\n\t\t\t\t\tthis.snapshot = null;\n\t\t\t\t\tthis.isPending = false;\n\t\t\t\t\tthis.statusUnsub?.();\n\t\t\t\t\tthis.statusUnsub = null;\n\t\t\t\t\tthis.host.requestUpdate();\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\tthis.error = status.lastError;\n\t\t\t\t\tthis.rollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\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> implements ReactiveController {\n\tprivate options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n\tprivate _system: SingleModuleSystem<M> | null = null;\n\n\tconstructor(host: ReactiveControllerHost, options: ModuleDef<M> | CreateSystemOptionsSingle<M>) {\n\t\tthis.options = options;\n\t\thost.addController(this);\n\t}\n\n\tget system(): SingleModuleSystem<M> {\n\t\tif (!this._system) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[Directive] SystemController.system is not available. \" +\n\t\t\t\t\"This can happen if:\\n\" +\n\t\t\t\t\" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n\t\t\t\t\" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n\t\t\t\t\"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n\t\t\t\t\"or after the element is connected to the DOM.\",\n\t\t\t);\n\t\t}\n\t\treturn this._system;\n\t}\n\n\thostConnected(): void {\n\t\tconst isModule = \"id\" in this.options && \"schema\" in this.options;\n\t\tconst system = isModule\n\t\t\t? createSystem({ module: this.options as ModuleDef<M> })\n\t\t\t: createSystem(this.options as CreateSystemOptionsSingle<M>);\n\t\tthis._system = system as unknown as SingleModuleSystem<M>;\n\t\tthis._system.start();\n\t}\n\n\thostDisconnected(): void {\n\t\tthis._system?.destroy();\n\t\tthis._system = null;\n\t}\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> implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\tprivate moduleDef: ModuleDef<M>;\n\tprivate config?: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\tplugins?: Plugin<any>[];\n\t\tdebug?: DebugConfig;\n\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\ttickMs?: number;\n\t\tzeroConfig?: boolean;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\tinitialFacts?: Record<string, any>;\n\t\tstatus?: boolean;\n\t};\n\n\tprivate _system: SingleModuleSystem<M> | null = null;\n\tprivate unsubFacts?: () => void;\n\tprivate unsubDerived?: () => void;\n\n\tfacts: InferFacts<M> = {} as InferFacts<M>;\n\tderived: InferDerivations<M> = {} as InferDerivations<M>;\n\tstatusPlugin?: StatusPlugin;\n\n\tget system(): SingleModuleSystem<M> {\n\t\tif (!this._system) {\n\t\t\tthrow new Error(\"[Directive] ModuleController.system is not available before hostConnected.\");\n\t\t}\n\t\treturn this._system;\n\t}\n\n\tget events(): SingleModuleSystem<M>[\"events\"] {\n\t\treturn this.system.events;\n\t}\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\tmoduleDef: ModuleDef<M>,\n\t\tconfig?: {\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\t\tplugins?: Plugin<any>[];\n\t\t\tdebug?: DebugConfig;\n\t\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\t\ttickMs?: number;\n\t\t\tzeroConfig?: boolean;\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\t\tinitialFacts?: Record<string, any>;\n\t\t\tstatus?: boolean;\n\t\t},\n\t) {\n\t\tthis.host = host;\n\t\tthis.moduleDef = moduleDef;\n\t\tthis.config = config;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tconst allPlugins = [...(this.config?.plugins ?? [])];\n\n\t\tif (this.config?.status) {\n\t\t\tconst sp = createRequirementStatusPlugin();\n\t\t\tthis.statusPlugin = sp;\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n\t\t\tallPlugins.push(sp.plugin as Plugin<any>);\n\t\t}\n\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n\t\tconst system = createSystem({\n\t\t\tmodule: this.moduleDef,\n\t\t\tplugins: allPlugins.length > 0 ? allPlugins : undefined,\n\t\t\tdebug: this.config?.debug,\n\t\t\terrorBoundary: this.config?.errorBoundary,\n\t\t\ttickMs: this.config?.tickMs,\n\t\t\tzeroConfig: this.config?.zeroConfig,\n\t\t\tinitialFacts: this.config?.initialFacts,\n\t\t} as any) as unknown as SingleModuleSystem<M>;\n\n\t\tthis._system = system;\n\t\tsystem.start();\n\n\t\t// Subscribe to all facts\n\t\tthis.facts = system.facts.$store.toObject() as InferFacts<M>;\n\t\tthis.unsubFacts = system.facts.$store.subscribeAll(() => {\n\t\t\tthis.facts = system.facts.$store.toObject() as InferFacts<M>;\n\t\t\tthis.host.requestUpdate();\n\t\t});\n\n\t\t// Subscribe to all derivations\n\t\tconst derivationKeys = Object.keys(system.derive ?? {});\n\t\tconst getDerived = (): InferDerivations<M> => {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const key of derivationKeys) {\n\t\t\t\tresult[key] = system.read(key);\n\t\t\t}\n\t\t\treturn result as InferDerivations<M>;\n\t\t};\n\t\tthis.derived = getDerived();\n\n\t\tif (derivationKeys.length > 0) {\n\t\t\tthis.unsubDerived = system.subscribe(derivationKeys, () => {\n\t\t\t\tthis.derived = getDerived();\n\t\t\t\tthis.host.requestUpdate();\n\t\t\t});\n\t\t}\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubFacts?.();\n\t\tthis.unsubDerived?.();\n\t\tthis._system?.destroy();\n\t\tthis._system = null;\n\t}\n\n\tdispatch(event: InferEvents<M>): void {\n\t\tthis.system.dispatch(event);\n\t}\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tkey: string | string[],\n): DerivedController<T> {\n\treturn new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): FactController<T> {\n\treturn 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\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\toptions?: { throttleMs?: number },\n): InspectController {\n\treturn new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n\thost: ReactiveControllerHost,\n\tstatusPlugin: StatusPlugin,\n\ttype: string,\n): RequirementStatusController {\n\treturn new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n\tcallback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n\treturn new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tselector: (state: Record<string, unknown>) => R,\n\tequalityFn: (a: R, b: R) => boolean = defaultEquality,\n\toptions?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n\treturn new DirectiveSelectorController<R>(host, system, selector, equalityFn, options);\n}\n\nexport function createExplain(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): ExplainController {\n\treturn new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): ConstraintStatusController {\n\treturn new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tstatusPlugin?: StatusPlugin,\n\trequirementType?: string,\n): OptimisticUpdateController {\n\treturn new OptimisticUpdateController(host, system, statusPlugin, requirementType);\n}\n\nexport function createModule<M extends ModuleSchema>(\n\thost: ReactiveControllerHost,\n\tmoduleDef: ModuleDef<M>,\n\tconfig?: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\tplugins?: Plugin<any>[];\n\t\tdebug?: DebugConfig;\n\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\ttickMs?: number;\n\t\tzeroConfig?: boolean;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\tinitialFacts?: Record<string, any>;\n\t\tstatus?: boolean;\n\t},\n): ModuleController<M> {\n\treturn new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n\tsystem: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n\tassertSystem(\"useDispatch\", system);\n\treturn (event: InferEvents<M>) => {\n\t\tsystem.dispatch(event);\n\t};\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n\tsystem: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n\tassertSystem(\"useEvents\", system);\n\treturn system.events;\n}\n\n/**\n * Reactive controller for time-travel state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private tt = new TimeTravelController(this, system);\n * render() {\n * const { canUndo, undo } = this.tt.value ?? {};\n * return html`<button ?disabled=${!canUndo} @click=${undo}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class TimeTravelController implements ReactiveController {\n\tvalue: TimeTravelState | null = null;\n\tprivate _unsub?: () => void;\n\n\tconstructor(\n\t\tprivate _host: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tprivate _system: SingleModuleSystem<any>,\n\t) {\n\t\tthis._host.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.value = buildTimeTravelState(this._system);\n\t\tthis._unsub = this._system.onTimeTravelChange(() => {\n\t\t\tthis.value = buildTimeTravelState(this._system);\n\t\t\tthis._host.requestUpdate();\n\t\t});\n\t}\n\n\thostDisconnected(): void {\n\t\tthis._unsub?.();\n\t\tthis._unsub = undefined;\n\t}\n}\n\n/**\n * Functional helper for time-travel state (non-reactive, snapshot).\n * For reactive updates, use TimeTravelController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useTimeTravel(system: SingleModuleSystem<any>): TimeTravelState | null {\n\tassertSystem(\"useTimeTravel\", system);\n\treturn buildTimeTravelState(system);\n}\n\nexport function getDerived<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n): () => T {\n\treturn () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): () => T | undefined {\n\treturn () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n\tcreateDerived: <K extends keyof InferDerivations<M>>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => DerivedController<InferDerivations<M>[K]>;\n\tcreateFact: <K extends keyof InferFacts<M>>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tfactKey: K,\n\t) => FactController<InferFacts<M>[K]>;\n\tuseDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;\n\tuseEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n\tcreateWatch: <K extends string>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tkey: K,\n\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t) => WatchController<unknown>;\n} {\n\treturn {\n\t\tcreateDerived: <K extends keyof InferDerivations<M>>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tderivationId: K,\n\t\t) => createDerived<InferDerivations<M>[K]>(host, system, derivationId as string),\n\t\tcreateFact: <K extends keyof InferFacts<M>>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tfactKey: K,\n\t\t) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n\t\tuseDispatch: (system: SingleModuleSystem<M>) => {\n\t\t\treturn (event: InferEvents<M>) => {\n\t\t\t\tsystem.dispatch(event);\n\t\t\t};\n\t\t},\n\t\tuseEvents: (system: SingleModuleSystem<M>) => system.events,\n\t\tcreateWatch: <K extends string>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tkey: K,\n\t\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t\t) => createWatch<unknown>(host, system, key, callback),\n\t};\n}\n\n"]}
@@ -0,0 +1,285 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import { SingleModuleSystem, ModuleSchema, InferFacts, InferDerivations, createRequirementStatusPlugin, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, InferEvents, RequirementTypeStatus, CreateSystemOptionsSingle, TimeTravelState } from '@directive-run/core';
3
+ export { RequirementTypeStatus } from '@directive-run/core';
4
+ import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
5
+ export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
6
+
7
+ /**
8
+ * Lit Adapter - Consolidated Web Components integration for Directive
9
+ *
10
+ * Controllers: DerivedController, FactController,
11
+ * InspectController (with throttle), RequirementStatusController,
12
+ * DirectiveSelectorController,
13
+ * WatchController (with fact mode), SystemController,
14
+ * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController
15
+ *
16
+ * Factories: createDerived, createFact, createInspect,
17
+ * createRequirementStatus, createWatch,
18
+ * createDirectiveSelector, useDispatch, useEvents, useTimeTravel,
19
+ * getDerived, getFact, createTypedHooks, shallowEqual
20
+ */
21
+
22
+ /** Type for the requirement status plugin return value */
23
+ type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
24
+ /**
25
+ * Context key for Directive system.
26
+ * Use with @lit/context for dependency injection across shadow DOM boundaries.
27
+ */
28
+ declare const directiveContext: unique symbol;
29
+ /**
30
+ * Base controller that manages system subscription lifecycle.
31
+ */
32
+ declare abstract class DirectiveController implements ReactiveController {
33
+ protected host: ReactiveControllerHost;
34
+ protected system: SingleModuleSystem<any>;
35
+ protected unsubscribe?: () => void;
36
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>);
37
+ hostConnected(): void;
38
+ hostDisconnected(): void;
39
+ protected abstract subscribe(): void;
40
+ protected requestUpdate(): void;
41
+ }
42
+ /**
43
+ * Reactive controller for derivations.
44
+ * Accepts a single key (string) or an array of keys (string[]).
45
+ * - Single key: `.value` returns `T`
46
+ * - Array of keys: `.value` returns `Record<string, unknown>`
47
+ */
48
+ declare class DerivedController<T> extends DirectiveController {
49
+ private keys;
50
+ private isMulti;
51
+ value: T;
52
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string | string[]);
53
+ private getValues;
54
+ protected subscribe(): void;
55
+ }
56
+ /**
57
+ * Reactive controller for a single fact value.
58
+ */
59
+ declare class FactController<T> extends DirectiveController {
60
+ private factKey;
61
+ value: T | undefined;
62
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, factKey: string);
63
+ protected subscribe(): void;
64
+ }
65
+ /**
66
+ * Consolidated inspection controller.
67
+ * Returns InspectState with optional throttling.
68
+ */
69
+ declare class InspectController extends DirectiveController {
70
+ value: InspectState;
71
+ private throttleMs;
72
+ private throttleCleanup?;
73
+ private unsubSettled?;
74
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: {
75
+ throttleMs?: number;
76
+ });
77
+ protected subscribe(): void;
78
+ hostDisconnected(): void;
79
+ }
80
+ /**
81
+ * Reactive controller for requirement status.
82
+ */
83
+ declare class RequirementStatusController implements ReactiveController {
84
+ private host;
85
+ private statusPlugin;
86
+ private type;
87
+ private unsubscribe?;
88
+ value: RequirementTypeStatus;
89
+ constructor(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string);
90
+ hostConnected(): void;
91
+ hostDisconnected(): void;
92
+ }
93
+ /**
94
+ * Reactive controller for selecting across all facts.
95
+ * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.
96
+ */
97
+ declare class DirectiveSelectorController<R> extends DirectiveController {
98
+ private selector;
99
+ private equalityFn;
100
+ private autoTrack;
101
+ private deriveKeySet;
102
+ private trackedFactKeys;
103
+ private trackedDeriveKeys;
104
+ private unsubs;
105
+ value: R;
106
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, selector: (state: Record<string, unknown>) => R, equalityFn?: (a: R, b: R) => boolean, options?: {
107
+ autoTrack?: boolean;
108
+ });
109
+ private runWithTracking;
110
+ private resubscribe;
111
+ protected subscribe(): void;
112
+ hostDisconnected(): void;
113
+ }
114
+ /**
115
+ * Reactive controller that watches a fact or derivation and calls a callback on change.
116
+ * The key is auto-detected — works with both fact keys and derivation keys.
117
+ */
118
+ declare class WatchController<T> extends DirectiveController {
119
+ private key;
120
+ private callback;
121
+ /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */
122
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string, callback: (newValue: T, previousValue: T | undefined) => void);
123
+ /**
124
+ * Watch a fact by explicit options.
125
+ * @deprecated Use `new WatchController(host, system, factKey, callback)` instead — facts are now auto-detected.
126
+ */
127
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options: {
128
+ kind: "fact";
129
+ factKey: string;
130
+ }, callback: (newValue: T, previousValue: T | undefined) => void);
131
+ protected subscribe(): void;
132
+ }
133
+ /**
134
+ * Reactive controller for requirement explanations.
135
+ */
136
+ declare class ExplainController extends DirectiveController {
137
+ private requirementId;
138
+ value: string | null;
139
+ private unsubSettled?;
140
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string);
141
+ protected subscribe(): void;
142
+ hostDisconnected(): void;
143
+ }
144
+ /**
145
+ * Reactive controller for constraint status.
146
+ */
147
+ declare class ConstraintStatusController extends DirectiveController {
148
+ private constraintId?;
149
+ value: ConstraintInfo[] | ConstraintInfo | null;
150
+ private unsubSettled?;
151
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string);
152
+ private getVal;
153
+ protected subscribe(): void;
154
+ hostDisconnected(): void;
155
+ }
156
+ /**
157
+ * Reactive controller for optimistic updates.
158
+ */
159
+ declare class OptimisticUpdateController implements ReactiveController {
160
+ private host;
161
+ private system;
162
+ private statusPlugin?;
163
+ private requirementType?;
164
+ private snapshot;
165
+ private statusUnsub;
166
+ isPending: boolean;
167
+ error: Error | null;
168
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string);
169
+ hostConnected(): void;
170
+ hostDisconnected(): void;
171
+ rollback(): void;
172
+ mutate(updateFn: () => void): void;
173
+ }
174
+ /**
175
+ * Reactive controller that creates and manages a Directive system.
176
+ * The system is automatically started when the host connects and destroyed when it disconnects.
177
+ */
178
+ declare class SystemController<M extends ModuleSchema> implements ReactiveController {
179
+ private options;
180
+ private _system;
181
+ constructor(host: ReactiveControllerHost, options: ModuleDef<M> | CreateSystemOptionsSingle<M>);
182
+ get system(): SingleModuleSystem<M>;
183
+ hostConnected(): void;
184
+ hostDisconnected(): void;
185
+ }
186
+ /**
187
+ * Module controller — zero-config all-in-one.
188
+ * Creates system, starts it, subscribes to all facts/derivations.
189
+ */
190
+ declare class ModuleController<M extends ModuleSchema> implements ReactiveController {
191
+ private host;
192
+ private moduleDef;
193
+ private config?;
194
+ private _system;
195
+ private unsubFacts?;
196
+ private unsubDerived?;
197
+ facts: InferFacts<M>;
198
+ derived: InferDerivations<M>;
199
+ statusPlugin?: StatusPlugin;
200
+ get system(): SingleModuleSystem<M>;
201
+ get events(): SingleModuleSystem<M>["events"];
202
+ constructor(host: ReactiveControllerHost, moduleDef: ModuleDef<M>, config?: {
203
+ plugins?: Plugin<any>[];
204
+ debug?: DebugConfig;
205
+ errorBoundary?: ErrorBoundaryConfig;
206
+ tickMs?: number;
207
+ zeroConfig?: boolean;
208
+ initialFacts?: Record<string, any>;
209
+ status?: boolean;
210
+ });
211
+ hostConnected(): void;
212
+ hostDisconnected(): void;
213
+ dispatch(event: InferEvents<M>): void;
214
+ }
215
+ declare function createDerived<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string | string[]): DerivedController<T>;
216
+ declare function createFact<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, factKey: string): FactController<T>;
217
+ /**
218
+ * Create an inspect controller.
219
+ * Returns InspectState; pass `{ throttleMs }` for throttled updates.
220
+ */
221
+ declare function createInspect(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: {
222
+ throttleMs?: number;
223
+ }): InspectController;
224
+ declare function createRequirementStatus(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string): RequirementStatusController;
225
+ declare function createWatch<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, derivationId: string, callback: (newValue: T, previousValue: T | undefined) => void): WatchController<T>;
226
+ declare function createDirectiveSelector<R>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, selector: (state: Record<string, unknown>) => R, equalityFn?: (a: R, b: R) => boolean, options?: {
227
+ autoTrack?: boolean;
228
+ }): DirectiveSelectorController<R>;
229
+ declare function createExplain(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string): ExplainController;
230
+ declare function createConstraintStatus(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string): ConstraintStatusController;
231
+ declare function createOptimisticUpdate(host: ReactiveControllerHost, system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateController;
232
+ declare function createModule<M extends ModuleSchema>(host: ReactiveControllerHost, moduleDef: ModuleDef<M>, config?: {
233
+ plugins?: Plugin<any>[];
234
+ debug?: DebugConfig;
235
+ errorBoundary?: ErrorBoundaryConfig;
236
+ tickMs?: number;
237
+ zeroConfig?: boolean;
238
+ initialFacts?: Record<string, any>;
239
+ status?: boolean;
240
+ }): ModuleController<M>;
241
+ declare function useDispatch<M extends ModuleSchema = ModuleSchema>(system: SingleModuleSystem<M>): (event: InferEvents<M>) => void;
242
+ /**
243
+ * Returns the system's events dispatcher.
244
+ */
245
+ declare function useEvents<M extends ModuleSchema = ModuleSchema>(system: SingleModuleSystem<M>): SingleModuleSystem<M>["events"];
246
+ /**
247
+ * Reactive controller for time-travel state.
248
+ * Triggers host updates when snapshots change or navigation occurs.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * class MyElement extends LitElement {
253
+ * private tt = new TimeTravelController(this, system);
254
+ * render() {
255
+ * const { canUndo, undo } = this.tt.value ?? {};
256
+ * return html`<button ?disabled=${!canUndo} @click=${undo}>Undo</button>`;
257
+ * }
258
+ * }
259
+ * ```
260
+ */
261
+ declare class TimeTravelController implements ReactiveController {
262
+ private _host;
263
+ private _system;
264
+ value: TimeTravelState | null;
265
+ private _unsub?;
266
+ constructor(_host: ReactiveControllerHost, _system: SingleModuleSystem<any>);
267
+ hostConnected(): void;
268
+ hostDisconnected(): void;
269
+ }
270
+ /**
271
+ * Functional helper for time-travel state (non-reactive, snapshot).
272
+ * For reactive updates, use TimeTravelController.
273
+ */
274
+ declare function useTimeTravel(system: SingleModuleSystem<any>): TimeTravelState | null;
275
+ declare function getDerived<T>(system: SingleModuleSystem<any>, derivationId: string): () => T;
276
+ declare function getFact<T>(system: SingleModuleSystem<any>, factKey: string): () => T | undefined;
277
+ declare function createTypedHooks<M extends ModuleSchema>(): {
278
+ createDerived: <K extends keyof InferDerivations<M>>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, derivationId: K) => DerivedController<InferDerivations<M>[K]>;
279
+ createFact: <K extends keyof InferFacts<M>>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, factKey: K) => FactController<InferFacts<M>[K]>;
280
+ useDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;
281
+ useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>["events"];
282
+ createWatch: <K extends string>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => WatchController<unknown>;
283
+ };
284
+
285
+ export { ConstraintStatusController, DerivedController, DirectiveSelectorController, ExplainController, FactController, InspectController, ModuleController, OptimisticUpdateController, RequirementStatusController, type StatusPlugin, SystemController, TimeTravelController, WatchController, createConstraintStatus, createDerived, createDirectiveSelector, createExplain, createFact, createInspect, createModule, createOptimisticUpdate, createRequirementStatus, createTypedHooks, createWatch, directiveContext, getDerived, getFact, useDispatch, useEvents, useTimeTravel };
@@ -0,0 +1,285 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import { SingleModuleSystem, ModuleSchema, InferFacts, InferDerivations, createRequirementStatusPlugin, ModuleDef, Plugin, DebugConfig, ErrorBoundaryConfig, InferEvents, RequirementTypeStatus, CreateSystemOptionsSingle, TimeTravelState } from '@directive-run/core';
3
+ export { RequirementTypeStatus } from '@directive-run/core';
4
+ import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils';
5
+ export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
6
+
7
+ /**
8
+ * Lit Adapter - Consolidated Web Components integration for Directive
9
+ *
10
+ * Controllers: DerivedController, FactController,
11
+ * InspectController (with throttle), RequirementStatusController,
12
+ * DirectiveSelectorController,
13
+ * WatchController (with fact mode), SystemController,
14
+ * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController
15
+ *
16
+ * Factories: createDerived, createFact, createInspect,
17
+ * createRequirementStatus, createWatch,
18
+ * createDirectiveSelector, useDispatch, useEvents, useTimeTravel,
19
+ * getDerived, getFact, createTypedHooks, shallowEqual
20
+ */
21
+
22
+ /** Type for the requirement status plugin return value */
23
+ type StatusPlugin = ReturnType<typeof createRequirementStatusPlugin>;
24
+ /**
25
+ * Context key for Directive system.
26
+ * Use with @lit/context for dependency injection across shadow DOM boundaries.
27
+ */
28
+ declare const directiveContext: unique symbol;
29
+ /**
30
+ * Base controller that manages system subscription lifecycle.
31
+ */
32
+ declare abstract class DirectiveController implements ReactiveController {
33
+ protected host: ReactiveControllerHost;
34
+ protected system: SingleModuleSystem<any>;
35
+ protected unsubscribe?: () => void;
36
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>);
37
+ hostConnected(): void;
38
+ hostDisconnected(): void;
39
+ protected abstract subscribe(): void;
40
+ protected requestUpdate(): void;
41
+ }
42
+ /**
43
+ * Reactive controller for derivations.
44
+ * Accepts a single key (string) or an array of keys (string[]).
45
+ * - Single key: `.value` returns `T`
46
+ * - Array of keys: `.value` returns `Record<string, unknown>`
47
+ */
48
+ declare class DerivedController<T> extends DirectiveController {
49
+ private keys;
50
+ private isMulti;
51
+ value: T;
52
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string | string[]);
53
+ private getValues;
54
+ protected subscribe(): void;
55
+ }
56
+ /**
57
+ * Reactive controller for a single fact value.
58
+ */
59
+ declare class FactController<T> extends DirectiveController {
60
+ private factKey;
61
+ value: T | undefined;
62
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, factKey: string);
63
+ protected subscribe(): void;
64
+ }
65
+ /**
66
+ * Consolidated inspection controller.
67
+ * Returns InspectState with optional throttling.
68
+ */
69
+ declare class InspectController extends DirectiveController {
70
+ value: InspectState;
71
+ private throttleMs;
72
+ private throttleCleanup?;
73
+ private unsubSettled?;
74
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: {
75
+ throttleMs?: number;
76
+ });
77
+ protected subscribe(): void;
78
+ hostDisconnected(): void;
79
+ }
80
+ /**
81
+ * Reactive controller for requirement status.
82
+ */
83
+ declare class RequirementStatusController implements ReactiveController {
84
+ private host;
85
+ private statusPlugin;
86
+ private type;
87
+ private unsubscribe?;
88
+ value: RequirementTypeStatus;
89
+ constructor(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string);
90
+ hostConnected(): void;
91
+ hostDisconnected(): void;
92
+ }
93
+ /**
94
+ * Reactive controller for selecting across all facts.
95
+ * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`.
96
+ */
97
+ declare class DirectiveSelectorController<R> extends DirectiveController {
98
+ private selector;
99
+ private equalityFn;
100
+ private autoTrack;
101
+ private deriveKeySet;
102
+ private trackedFactKeys;
103
+ private trackedDeriveKeys;
104
+ private unsubs;
105
+ value: R;
106
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, selector: (state: Record<string, unknown>) => R, equalityFn?: (a: R, b: R) => boolean, options?: {
107
+ autoTrack?: boolean;
108
+ });
109
+ private runWithTracking;
110
+ private resubscribe;
111
+ protected subscribe(): void;
112
+ hostDisconnected(): void;
113
+ }
114
+ /**
115
+ * Reactive controller that watches a fact or derivation and calls a callback on change.
116
+ * The key is auto-detected — works with both fact keys and derivation keys.
117
+ */
118
+ declare class WatchController<T> extends DirectiveController {
119
+ private key;
120
+ private callback;
121
+ /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */
122
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string, callback: (newValue: T, previousValue: T | undefined) => void);
123
+ /**
124
+ * Watch a fact by explicit options.
125
+ * @deprecated Use `new WatchController(host, system, factKey, callback)` instead — facts are now auto-detected.
126
+ */
127
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options: {
128
+ kind: "fact";
129
+ factKey: string;
130
+ }, callback: (newValue: T, previousValue: T | undefined) => void);
131
+ protected subscribe(): void;
132
+ }
133
+ /**
134
+ * Reactive controller for requirement explanations.
135
+ */
136
+ declare class ExplainController extends DirectiveController {
137
+ private requirementId;
138
+ value: string | null;
139
+ private unsubSettled?;
140
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string);
141
+ protected subscribe(): void;
142
+ hostDisconnected(): void;
143
+ }
144
+ /**
145
+ * Reactive controller for constraint status.
146
+ */
147
+ declare class ConstraintStatusController extends DirectiveController {
148
+ private constraintId?;
149
+ value: ConstraintInfo[] | ConstraintInfo | null;
150
+ private unsubSettled?;
151
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string);
152
+ private getVal;
153
+ protected subscribe(): void;
154
+ hostDisconnected(): void;
155
+ }
156
+ /**
157
+ * Reactive controller for optimistic updates.
158
+ */
159
+ declare class OptimisticUpdateController implements ReactiveController {
160
+ private host;
161
+ private system;
162
+ private statusPlugin?;
163
+ private requirementType?;
164
+ private snapshot;
165
+ private statusUnsub;
166
+ isPending: boolean;
167
+ error: Error | null;
168
+ constructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string);
169
+ hostConnected(): void;
170
+ hostDisconnected(): void;
171
+ rollback(): void;
172
+ mutate(updateFn: () => void): void;
173
+ }
174
+ /**
175
+ * Reactive controller that creates and manages a Directive system.
176
+ * The system is automatically started when the host connects and destroyed when it disconnects.
177
+ */
178
+ declare class SystemController<M extends ModuleSchema> implements ReactiveController {
179
+ private options;
180
+ private _system;
181
+ constructor(host: ReactiveControllerHost, options: ModuleDef<M> | CreateSystemOptionsSingle<M>);
182
+ get system(): SingleModuleSystem<M>;
183
+ hostConnected(): void;
184
+ hostDisconnected(): void;
185
+ }
186
+ /**
187
+ * Module controller — zero-config all-in-one.
188
+ * Creates system, starts it, subscribes to all facts/derivations.
189
+ */
190
+ declare class ModuleController<M extends ModuleSchema> implements ReactiveController {
191
+ private host;
192
+ private moduleDef;
193
+ private config?;
194
+ private _system;
195
+ private unsubFacts?;
196
+ private unsubDerived?;
197
+ facts: InferFacts<M>;
198
+ derived: InferDerivations<M>;
199
+ statusPlugin?: StatusPlugin;
200
+ get system(): SingleModuleSystem<M>;
201
+ get events(): SingleModuleSystem<M>["events"];
202
+ constructor(host: ReactiveControllerHost, moduleDef: ModuleDef<M>, config?: {
203
+ plugins?: Plugin<any>[];
204
+ debug?: DebugConfig;
205
+ errorBoundary?: ErrorBoundaryConfig;
206
+ tickMs?: number;
207
+ zeroConfig?: boolean;
208
+ initialFacts?: Record<string, any>;
209
+ status?: boolean;
210
+ });
211
+ hostConnected(): void;
212
+ hostDisconnected(): void;
213
+ dispatch(event: InferEvents<M>): void;
214
+ }
215
+ declare function createDerived<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, key: string | string[]): DerivedController<T>;
216
+ declare function createFact<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, factKey: string): FactController<T>;
217
+ /**
218
+ * Create an inspect controller.
219
+ * Returns InspectState; pass `{ throttleMs }` for throttled updates.
220
+ */
221
+ declare function createInspect(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: {
222
+ throttleMs?: number;
223
+ }): InspectController;
224
+ declare function createRequirementStatus(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string): RequirementStatusController;
225
+ declare function createWatch<T>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, derivationId: string, callback: (newValue: T, previousValue: T | undefined) => void): WatchController<T>;
226
+ declare function createDirectiveSelector<R>(host: ReactiveControllerHost, system: SingleModuleSystem<any>, selector: (state: Record<string, unknown>) => R, equalityFn?: (a: R, b: R) => boolean, options?: {
227
+ autoTrack?: boolean;
228
+ }): DirectiveSelectorController<R>;
229
+ declare function createExplain(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string): ExplainController;
230
+ declare function createConstraintStatus(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string): ConstraintStatusController;
231
+ declare function createOptimisticUpdate(host: ReactiveControllerHost, system: SingleModuleSystem<any>, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateController;
232
+ declare function createModule<M extends ModuleSchema>(host: ReactiveControllerHost, moduleDef: ModuleDef<M>, config?: {
233
+ plugins?: Plugin<any>[];
234
+ debug?: DebugConfig;
235
+ errorBoundary?: ErrorBoundaryConfig;
236
+ tickMs?: number;
237
+ zeroConfig?: boolean;
238
+ initialFacts?: Record<string, any>;
239
+ status?: boolean;
240
+ }): ModuleController<M>;
241
+ declare function useDispatch<M extends ModuleSchema = ModuleSchema>(system: SingleModuleSystem<M>): (event: InferEvents<M>) => void;
242
+ /**
243
+ * Returns the system's events dispatcher.
244
+ */
245
+ declare function useEvents<M extends ModuleSchema = ModuleSchema>(system: SingleModuleSystem<M>): SingleModuleSystem<M>["events"];
246
+ /**
247
+ * Reactive controller for time-travel state.
248
+ * Triggers host updates when snapshots change or navigation occurs.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * class MyElement extends LitElement {
253
+ * private tt = new TimeTravelController(this, system);
254
+ * render() {
255
+ * const { canUndo, undo } = this.tt.value ?? {};
256
+ * return html`<button ?disabled=${!canUndo} @click=${undo}>Undo</button>`;
257
+ * }
258
+ * }
259
+ * ```
260
+ */
261
+ declare class TimeTravelController implements ReactiveController {
262
+ private _host;
263
+ private _system;
264
+ value: TimeTravelState | null;
265
+ private _unsub?;
266
+ constructor(_host: ReactiveControllerHost, _system: SingleModuleSystem<any>);
267
+ hostConnected(): void;
268
+ hostDisconnected(): void;
269
+ }
270
+ /**
271
+ * Functional helper for time-travel state (non-reactive, snapshot).
272
+ * For reactive updates, use TimeTravelController.
273
+ */
274
+ declare function useTimeTravel(system: SingleModuleSystem<any>): TimeTravelState | null;
275
+ declare function getDerived<T>(system: SingleModuleSystem<any>, derivationId: string): () => T;
276
+ declare function getFact<T>(system: SingleModuleSystem<any>, factKey: string): () => T | undefined;
277
+ declare function createTypedHooks<M extends ModuleSchema>(): {
278
+ createDerived: <K extends keyof InferDerivations<M>>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, derivationId: K) => DerivedController<InferDerivations<M>[K]>;
279
+ createFact: <K extends keyof InferFacts<M>>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, factKey: K) => FactController<InferFacts<M>[K]>;
280
+ useDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;
281
+ useEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>["events"];
282
+ createWatch: <K extends string>(host: ReactiveControllerHost, system: SingleModuleSystem<M>, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => WatchController<unknown>;
283
+ };
284
+
285
+ export { ConstraintStatusController, DerivedController, DirectiveSelectorController, ExplainController, FactController, InspectController, ModuleController, OptimisticUpdateController, RequirementStatusController, type StatusPlugin, SystemController, TimeTravelController, WatchController, createConstraintStatus, createDerived, createDirectiveSelector, createExplain, createFact, createInspect, createModule, createOptimisticUpdate, createRequirementStatus, createTypedHooks, createWatch, directiveContext, getDerived, getFact, useDispatch, useEvents, useTimeTravel };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {defaultEquality,computeInspectState,createThrottle,runTrackedSelector,assertSystem,buildTimeTravelState,depsChanged}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';var E=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();});}},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();}},y=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();}},g=class extends r{key;callback;constructor(e,t,i,n){super(e,t),typeof i=="string"?this.key=i:this.key=i.factKey,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();}},m=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());}));}},C=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
+ 1. Accessed before hostConnected (e.g., in a class field initializer)
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;}},S=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,debug:this.config?.debug,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 I(s,e,t){return new d(s,e,t)}function w(s,e,t){return new h(s,e,t)}function U(s,e,t){return new v(s,e,t)}function _(s,e,t){return new y(s,e,t)}function H(s,e,t,i){return new g(s,e,t,i)}function V(s,e,t,i=defaultEquality,n){return new p(s,e,t,i,n)}function $(s,e,t){return new f(s,e,t)}function A(s,e,t){return new m(s,e,t)}function B(s,e,t,i){return new b(s,e,t,i)}function O(s,e,t){return new S(s,e,t)}function W(s){return assertSystem("useDispatch",s),e=>{s.dispatch(e);}}function z(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=buildTimeTravelState(this._system),this._unsub=this._system.onTimeTravelChange(()=>{this.value=buildTimeTravelState(this._system),this._host.requestUpdate();});}hostDisconnected(){this._unsub?.(),this._unsub=void 0;}};function j(s){return assertSystem("useTimeTravel",s),buildTimeTravelState(s)}function N(s,e){return ()=>s.read(e)}function L(s,e){return ()=>s.facts.$store.get(e)}function G(){return {createDerived:(s,e,t)=>I(s,e,t),createFact:(s,e,t)=>w(s,e,t),useDispatch:s=>e=>{s.dispatch(e);},useEvents:s=>s.events,createWatch:(s,e,t,i)=>H(s,e,t,i)}}export{m as ConstraintStatusController,d as DerivedController,p as DirectiveSelectorController,f as ExplainController,h as FactController,v as InspectController,S as ModuleController,b as OptimisticUpdateController,y as RequirementStatusController,C as SystemController,k as TimeTravelController,g as WatchController,A as createConstraintStatus,I as createDerived,V as createDirectiveSelector,$ as createExplain,w as createFact,U as createInspect,O as createModule,B as createOptimisticUpdate,_ as createRequirementStatus,G as createTypedHooks,H as createWatch,E as directiveContext,N as getDerived,L as getFact,W as useDispatch,z as useEvents,j as useTimeTravel};//# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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","keyOrOptions","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","TimeTravelController","_host","_system","buildTimeTravelState","useTimeTravel","getFact","createTypedHooks"],"mappings":"6SAgEO,IAAMA,CAAAA,CAAmB,MAAA,CAAO,WAAW,CAAA,CASnCC,CAAAA,CAAf,KAAiE,CACtD,IAAA,CAEA,MAAA,CACA,WAAA,CAGV,WAAA,CAAYC,CAAAA,CAA8BC,CAAAA,CAAiC,CAC1E,IAAA,CAAK,IAAA,CAAOD,CAAAA,CACZ,IAAA,CAAK,MAAA,CAASC,CAAAA,CACdD,CAAAA,CAAK,aAAA,CAAc,IAAI,EACxB,CAEA,aAAA,EAAsB,CACrB,IAAA,CAAK,SAAA,GACN,CAEA,gBAAA,EAAyB,CACxB,IAAA,CAAK,WAAA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CAAQ,CACtD,CACD","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, useTimeTravel,\n * getDerived, getFact, createTypedHooks, shallowEqual\n */\n\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport type {\n\tCreateSystemOptionsSingle,\n\tModuleSchema,\n\tModuleDef,\n\tPlugin,\n\tDebugConfig,\n\tErrorBoundaryConfig,\n\tInferFacts,\n\tInferDerivations,\n\tInferEvents,\n\tSingleModuleSystem,\n\tSystemSnapshot,\n\tTimeTravelState,\n} from \"@directive-run/core\";\nimport {\n\tcreateSystem,\n\tcreateRequirementStatusPlugin,\n} from \"@directive-run/core\";\nimport type { RequirementTypeStatus } from \"@directive-run/core\";\nimport {\n\ttype InspectState,\n\ttype ConstraintInfo,\n\ttype TrackedSelectorResult,\n\tcomputeInspectState,\n\tcreateThrottle,\n\tassertSystem,\n\tdefaultEquality,\n\tbuildTimeTravelState,\n\trunTrackedSelector,\n\tdepsChanged,\n\tshallowEqual,\n} from \"@directive-run/core/adapter-utils\";\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\tprotected host: ReactiveControllerHost;\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tprotected system: SingleModuleSystem<any>;\n\tprotected unsubscribe?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>) {\n\t\tthis.host = host;\n\t\tthis.system = system;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.subscribe();\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t}\n\n\tprotected abstract subscribe(): void;\n\n\tprotected requestUpdate(): void {\n\t\tthis.host.requestUpdate();\n\t}\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\tprivate keys: string[];\n\tprivate isMulti: boolean;\n\tvalue: T;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkey: string | string[],\n\t) {\n\t\tsuper(host, system);\n\t\tthis.isMulti = Array.isArray(key);\n\t\tthis.keys = this.isMulti ? (key as string[]) : [key as string];\n\t\tthis.value = this.getValues();\n\n\t\tif (process.env.NODE_ENV !== \"production\") {\n\t\t\tif (!this.isMulti && this.value === undefined) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Directive] DerivedController(\"${this.keys[0]}\") returned undefined. ` +\n\t\t\t\t\t`Check that \"${this.keys[0]}\" is defined in your module's derive property.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getValues(): T {\n\t\tif (this.isMulti) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const id of this.keys) {\n\t\t\t\tresult[id] = this.system.read(id);\n\t\t\t}\n\t\t\treturn result as T;\n\t\t}\n\t\treturn this.system.read(this.keys[0]!) as T;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.getValues();\n\t\tthis.unsubscribe = this.system.subscribe(this.keys, () => {\n\t\t\tthis.value = this.getValues();\n\t\t\tthis.requestUpdate();\n\t\t});\n\t}\n}\n\n/**\n * Reactive controller for a single fact value.\n */\nexport class FactController<T> extends DirectiveController {\n\tprivate factKey: string;\n\tvalue: T | undefined;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tfactKey: string,\n\t) {\n\t\tsuper(host, system);\n\t\tthis.factKey = factKey;\n\t\tthis.value = system.facts.$store.get(factKey) as T | undefined;\n\n\t\tif (process.env.NODE_ENV !== \"production\") {\n\t\t\tif (!system.facts.$store.has(factKey)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Directive] FactController(\"${factKey}\") — fact not found in store. ` +\n\t\t\t\t\t`Check that \"${factKey}\" is defined in your module's schema.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n\t\tthis.unsubscribe = this.system.facts.$store.subscribe(\n\t\t\t[this.factKey],\n\t\t\t() => {\n\t\t\t\tthis.value = this.system.facts.$store.get(this.factKey) as T | undefined;\n\t\t\t\tthis.requestUpdate();\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * Consolidated inspection controller.\n * Returns InspectState with optional throttling.\n */\nexport class InspectController extends DirectiveController {\n\tvalue: InspectState;\n\tprivate throttleMs: number;\n\tprivate throttleCleanup?: () => void;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, options?: { throttleMs?: number }) {\n\t\tsuper(host, system);\n\t\tthis.throttleMs = options?.throttleMs ?? 0;\n\t\tthis.value = computeInspectState(system);\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = computeInspectState(this.system);\n\n\t\tconst update = () => {\n\t\t\tthis.value = computeInspectState(this.system);\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tif (this.throttleMs > 0) {\n\t\t\tconst { throttled, cleanup } = createThrottle(update, this.throttleMs);\n\t\t\tthis.throttleCleanup = cleanup;\n\t\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(throttled);\n\t\t\tthis.unsubSettled = this.system.onSettledChange(throttled);\n\t\t} else {\n\t\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t\t}\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.throttleCleanup?.();\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for requirement status.\n */\nexport class RequirementStatusController implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\tprivate statusPlugin: StatusPlugin;\n\tprivate type: string;\n\tprivate unsubscribe?: () => void;\n\tvalue: RequirementTypeStatus;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\tstatusPlugin: StatusPlugin,\n\t\ttype: string,\n\t) {\n\t\tthis.host = host;\n\t\tthis.statusPlugin = statusPlugin;\n\t\tthis.type = type;\n\t\tthis.value = statusPlugin.getStatus(type);\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.value = this.statusPlugin.getStatus(this.type);\n\t\tthis.unsubscribe = this.statusPlugin.subscribe(() => {\n\t\t\tthis.value = this.statusPlugin.getStatus(this.type);\n\t\t\tthis.host.requestUpdate();\n\t\t});\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t}\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\tprivate selector: (state: Record<string, unknown>) => R;\n\tprivate equalityFn: (a: R, b: R) => boolean;\n\tprivate autoTrack: boolean;\n\tprivate deriveKeySet: Set<string>;\n\tprivate trackedFactKeys: string[] = [];\n\tprivate trackedDeriveKeys: string[] = [];\n\tprivate unsubs: Array<() => void> = [];\n\tvalue: R;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tselector: (state: Record<string, unknown>) => R,\n\t\tequalityFn: (a: R, b: R) => boolean = defaultEquality,\n\t\toptions?: { autoTrack?: boolean },\n\t) {\n\t\tsuper(host, system);\n\t\tthis.selector = selector;\n\t\tthis.equalityFn = equalityFn;\n\t\tthis.autoTrack = options?.autoTrack ?? true;\n\t\tthis.deriveKeySet = new Set(Object.keys(system.derive ?? {}));\n\n\t\tconst initial = this.runWithTracking();\n\t\tthis.value = initial.value;\n\t\tthis.trackedFactKeys = initial.factKeys;\n\t\tthis.trackedDeriveKeys = initial.deriveKeys;\n\t}\n\n\tprivate runWithTracking(): TrackedSelectorResult<R> {\n\t\treturn runTrackedSelector(this.system, this.deriveKeySet, this.selector);\n\t}\n\n\tprivate resubscribe(): void {\n\t\tfor (const unsub of this.unsubs) unsub();\n\t\tthis.unsubs = [];\n\n\t\tconst onUpdate = () => {\n\t\t\tconst result = this.runWithTracking();\n\t\t\tif (!this.equalityFn(this.value, result.value)) {\n\t\t\t\tthis.value = result.value;\n\t\t\t\tthis.requestUpdate();\n\t\t\t}\n\t\t\tif (this.autoTrack) {\n\t\t\t\t// Re-track: check if deps changed\n\t\t\t\tif (depsChanged(this.trackedFactKeys, result.factKeys, this.trackedDeriveKeys, result.deriveKeys)) {\n\t\t\t\t\tthis.trackedFactKeys = result.factKeys;\n\t\t\t\t\tthis.trackedDeriveKeys = result.deriveKeys;\n\t\t\t\t\tthis.resubscribe();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tif (this.autoTrack) {\n\t\t\tif (this.trackedFactKeys.length > 0) {\n\t\t\t\tthis.unsubs.push(this.system.facts.$store.subscribe(this.trackedFactKeys, onUpdate));\n\t\t\t} else if (this.trackedDeriveKeys.length === 0) {\n\t\t\t\tthis.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n\t\t\t}\n\t\t\tif (this.trackedDeriveKeys.length > 0) {\n\t\t\t\tthis.unsubs.push(this.system.subscribe(this.trackedDeriveKeys, onUpdate));\n\t\t\t}\n\t\t} else {\n\t\t\tthis.unsubs.push(this.system.facts.$store.subscribeAll(onUpdate));\n\t\t}\n\t}\n\n\tprotected subscribe(): void {\n\t\tconst result = this.runWithTracking();\n\t\tthis.value = result.value;\n\t\tthis.trackedFactKeys = result.factKeys;\n\t\tthis.trackedDeriveKeys = result.deriveKeys;\n\t\tthis.resubscribe();\n\t}\n\n\thostDisconnected(): void {\n\t\tfor (const unsub of this.unsubs) unsub();\n\t\tthis.unsubs = [];\n\t\tsuper.hostDisconnected();\n\t}\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\tprivate key: string;\n\tprivate callback: (newValue: T, previousValue: T | undefined) => void;\n\n\t/** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkey: string,\n\t\tcallback: (newValue: T, previousValue: T | undefined) => void,\n\t);\n\t/**\n\t * Watch a fact by explicit options.\n\t * @deprecated Use `new WatchController(host, system, factKey, callback)` instead — facts are now auto-detected.\n\t */\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\toptions: { kind: \"fact\"; factKey: string },\n\t\tcallback: (newValue: T, previousValue: T | undefined) => void,\n\t);\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tkeyOrOptions: string | { kind: \"fact\"; factKey: string },\n\t\tcallback?: (newValue: T, previousValue: T | undefined) => void,\n\t) {\n\t\tsuper(host, system);\n\t\tif (typeof keyOrOptions === \"string\") {\n\t\t\tthis.key = keyOrOptions;\n\t\t} else {\n\t\t\tthis.key = keyOrOptions.factKey;\n\t\t}\n\t\tthis.callback = callback!;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.unsubscribe = this.system.watch<T>(this.key, this.callback);\n\t}\n}\n\n// ============================================================================\n// New Controllers\n// ============================================================================\n\n/**\n * Reactive controller for requirement explanations.\n */\nexport class ExplainController extends DirectiveController {\n\tprivate requirementId: string;\n\tvalue: string | null;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, requirementId: string) {\n\t\tsuper(host, system);\n\t\tthis.requirementId = requirementId;\n\t\tthis.value = system.explain(requirementId);\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.system.explain(this.requirementId);\n\n\t\tconst update = () => {\n\t\t\tthis.value = this.system.explain(this.requirementId);\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for constraint status.\n */\nexport class ConstraintStatusController extends DirectiveController {\n\tprivate constraintId?: string;\n\tvalue: ConstraintInfo[] | ConstraintInfo | null;\n\tprivate unsubSettled?: () => void;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tconstructor(host: ReactiveControllerHost, system: SingleModuleSystem<any>, constraintId?: string) {\n\t\tsuper(host, system);\n\t\tthis.constraintId = constraintId;\n\t\tthis.value = this.getVal();\n\t}\n\n\tprivate getVal(): ConstraintInfo[] | ConstraintInfo | null {\n\t\tconst inspection = this.system.inspect();\n\t\tif (!this.constraintId) return inspection.constraints;\n\t\treturn inspection.constraints.find((c: ConstraintInfo) => c.id === this.constraintId) ?? null;\n\t}\n\n\tprotected subscribe(): void {\n\t\tthis.value = this.getVal();\n\n\t\tconst update = () => {\n\t\t\tthis.value = this.getVal();\n\t\t\tthis.requestUpdate();\n\t\t};\n\n\t\tthis.unsubscribe = this.system.facts.$store.subscribeAll(update);\n\t\tthis.unsubSettled = this.system.onSettledChange(update);\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubSettled?.();\n\t\tsuper.hostDisconnected();\n\t}\n}\n\n/**\n * Reactive controller for optimistic updates.\n */\nexport class OptimisticUpdateController implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tprivate system: SingleModuleSystem<any>;\n\tprivate statusPlugin?: StatusPlugin;\n\tprivate requirementType?: string;\n\tprivate snapshot: SystemSnapshot | null = null;\n\tprivate statusUnsub: (() => void) | null = null;\n\n\tisPending = false;\n\terror: Error | null = null;\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tsystem: SingleModuleSystem<any>,\n\t\tstatusPlugin?: StatusPlugin,\n\t\trequirementType?: string,\n\t) {\n\t\tthis.host = host;\n\t\tthis.system = system;\n\t\tthis.statusPlugin = statusPlugin;\n\t\tthis.requirementType = requirementType;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {}\n\n\thostDisconnected(): void {\n\t\tthis.statusUnsub?.();\n\t\tthis.statusUnsub = null;\n\t}\n\n\trollback(): void {\n\t\tif (this.snapshot) {\n\t\t\tthis.system.restore(this.snapshot);\n\t\t\tthis.snapshot = null;\n\t\t}\n\t\tthis.isPending = false;\n\t\tthis.error = null;\n\t\tthis.statusUnsub?.();\n\t\tthis.statusUnsub = null;\n\t\tthis.host.requestUpdate();\n\t}\n\n\tmutate(updateFn: () => void): void {\n\t\tthis.snapshot = this.system.getSnapshot();\n\t\tthis.isPending = true;\n\t\tthis.error = null;\n\t\tthis.system.batch(updateFn);\n\t\tthis.host.requestUpdate();\n\n\t\tif (this.statusPlugin && this.requirementType) {\n\t\t\tthis.statusUnsub?.();\n\t\t\tthis.statusUnsub = this.statusPlugin.subscribe(() => {\n\t\t\t\tconst status = this.statusPlugin!.getStatus(this.requirementType!);\n\t\t\t\tif (!status.isLoading && !status.hasError) {\n\t\t\t\t\tthis.snapshot = null;\n\t\t\t\t\tthis.isPending = false;\n\t\t\t\t\tthis.statusUnsub?.();\n\t\t\t\t\tthis.statusUnsub = null;\n\t\t\t\t\tthis.host.requestUpdate();\n\t\t\t\t} else if (status.hasError) {\n\t\t\t\t\tthis.error = status.lastError;\n\t\t\t\t\tthis.rollback();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\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> implements ReactiveController {\n\tprivate options: ModuleDef<M> | CreateSystemOptionsSingle<M>;\n\tprivate _system: SingleModuleSystem<M> | null = null;\n\n\tconstructor(host: ReactiveControllerHost, options: ModuleDef<M> | CreateSystemOptionsSingle<M>) {\n\t\tthis.options = options;\n\t\thost.addController(this);\n\t}\n\n\tget system(): SingleModuleSystem<M> {\n\t\tif (!this._system) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[Directive] SystemController.system is not available. \" +\n\t\t\t\t\"This can happen if:\\n\" +\n\t\t\t\t\" 1. Accessed before hostConnected (e.g., in a class field initializer)\\n\" +\n\t\t\t\t\" 2. Accessed after hostDisconnected (system was destroyed)\\n\" +\n\t\t\t\t\"Solution: Access system only in lifecycle methods (connectedCallback, render) \" +\n\t\t\t\t\"or after the element is connected to the DOM.\",\n\t\t\t);\n\t\t}\n\t\treturn this._system;\n\t}\n\n\thostConnected(): void {\n\t\tconst isModule = \"id\" in this.options && \"schema\" in this.options;\n\t\tconst system = isModule\n\t\t\t? createSystem({ module: this.options as ModuleDef<M> })\n\t\t\t: createSystem(this.options as CreateSystemOptionsSingle<M>);\n\t\tthis._system = system as unknown as SingleModuleSystem<M>;\n\t\tthis._system.start();\n\t}\n\n\thostDisconnected(): void {\n\t\tthis._system?.destroy();\n\t\tthis._system = null;\n\t}\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> implements ReactiveController {\n\tprivate host: ReactiveControllerHost;\n\tprivate moduleDef: ModuleDef<M>;\n\tprivate config?: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\tplugins?: Plugin<any>[];\n\t\tdebug?: DebugConfig;\n\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\ttickMs?: number;\n\t\tzeroConfig?: boolean;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\tinitialFacts?: Record<string, any>;\n\t\tstatus?: boolean;\n\t};\n\n\tprivate _system: SingleModuleSystem<M> | null = null;\n\tprivate unsubFacts?: () => void;\n\tprivate unsubDerived?: () => void;\n\n\tfacts: InferFacts<M> = {} as InferFacts<M>;\n\tderived: InferDerivations<M> = {} as InferDerivations<M>;\n\tstatusPlugin?: StatusPlugin;\n\n\tget system(): SingleModuleSystem<M> {\n\t\tif (!this._system) {\n\t\t\tthrow new Error(\"[Directive] ModuleController.system is not available before hostConnected.\");\n\t\t}\n\t\treturn this._system;\n\t}\n\n\tget events(): SingleModuleSystem<M>[\"events\"] {\n\t\treturn this.system.events;\n\t}\n\n\tconstructor(\n\t\thost: ReactiveControllerHost,\n\t\tmoduleDef: ModuleDef<M>,\n\t\tconfig?: {\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\t\tplugins?: Plugin<any>[];\n\t\t\tdebug?: DebugConfig;\n\t\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\t\ttickMs?: number;\n\t\t\tzeroConfig?: boolean;\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\t\tinitialFacts?: Record<string, any>;\n\t\t\tstatus?: boolean;\n\t\t},\n\t) {\n\t\tthis.host = host;\n\t\tthis.moduleDef = moduleDef;\n\t\tthis.config = config;\n\t\thost.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tconst allPlugins = [...(this.config?.plugins ?? [])];\n\n\t\tif (this.config?.status) {\n\t\t\tconst sp = createRequirementStatusPlugin();\n\t\t\tthis.statusPlugin = sp;\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin generic issues\n\t\t\tallPlugins.push(sp.plugin as Plugin<any>);\n\t\t}\n\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Required for overload compatibility\n\t\tconst system = createSystem({\n\t\t\tmodule: this.moduleDef,\n\t\t\tplugins: allPlugins.length > 0 ? allPlugins : undefined,\n\t\t\tdebug: this.config?.debug,\n\t\t\terrorBoundary: this.config?.errorBoundary,\n\t\t\ttickMs: this.config?.tickMs,\n\t\t\tzeroConfig: this.config?.zeroConfig,\n\t\t\tinitialFacts: this.config?.initialFacts,\n\t\t} as any) as unknown as SingleModuleSystem<M>;\n\n\t\tthis._system = system;\n\t\tsystem.start();\n\n\t\t// Subscribe to all facts\n\t\tthis.facts = system.facts.$store.toObject() as InferFacts<M>;\n\t\tthis.unsubFacts = system.facts.$store.subscribeAll(() => {\n\t\t\tthis.facts = system.facts.$store.toObject() as InferFacts<M>;\n\t\t\tthis.host.requestUpdate();\n\t\t});\n\n\t\t// Subscribe to all derivations\n\t\tconst derivationKeys = Object.keys(system.derive ?? {});\n\t\tconst getDerived = (): InferDerivations<M> => {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const key of derivationKeys) {\n\t\t\t\tresult[key] = system.read(key);\n\t\t\t}\n\t\t\treturn result as InferDerivations<M>;\n\t\t};\n\t\tthis.derived = getDerived();\n\n\t\tif (derivationKeys.length > 0) {\n\t\t\tthis.unsubDerived = system.subscribe(derivationKeys, () => {\n\t\t\t\tthis.derived = getDerived();\n\t\t\t\tthis.host.requestUpdate();\n\t\t\t});\n\t\t}\n\t}\n\n\thostDisconnected(): void {\n\t\tthis.unsubFacts?.();\n\t\tthis.unsubDerived?.();\n\t\tthis._system?.destroy();\n\t\tthis._system = null;\n\t}\n\n\tdispatch(event: InferEvents<M>): void {\n\t\tthis.system.dispatch(event);\n\t}\n}\n\n// ============================================================================\n// Factory Functions (active)\n// ============================================================================\n\nexport function createDerived<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tkey: string | string[],\n): DerivedController<T> {\n\treturn new DerivedController<T>(host, system, key);\n}\n\nexport function createFact<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): FactController<T> {\n\treturn 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\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\toptions?: { throttleMs?: number },\n): InspectController {\n\treturn new InspectController(host, system, options);\n}\n\nexport function createRequirementStatus(\n\thost: ReactiveControllerHost,\n\tstatusPlugin: StatusPlugin,\n\ttype: string,\n): RequirementStatusController {\n\treturn new RequirementStatusController(host, statusPlugin, type);\n}\n\nexport function createWatch<T>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n\tcallback: (newValue: T, previousValue: T | undefined) => void,\n): WatchController<T> {\n\treturn new WatchController<T>(host, system, derivationId, callback);\n}\n\nexport function createDirectiveSelector<R>(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tselector: (state: Record<string, unknown>) => R,\n\tequalityFn: (a: R, b: R) => boolean = defaultEquality,\n\toptions?: { autoTrack?: boolean },\n): DirectiveSelectorController<R> {\n\treturn new DirectiveSelectorController<R>(host, system, selector, equalityFn, options);\n}\n\nexport function createExplain(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\trequirementId: string,\n): ExplainController {\n\treturn new ExplainController(host, system, requirementId);\n}\n\nexport function createConstraintStatus(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tconstraintId?: string,\n): ConstraintStatusController {\n\treturn new ConstraintStatusController(host, system, constraintId);\n}\n\nexport function createOptimisticUpdate(\n\thost: ReactiveControllerHost,\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tstatusPlugin?: StatusPlugin,\n\trequirementType?: string,\n): OptimisticUpdateController {\n\treturn new OptimisticUpdateController(host, system, statusPlugin, requirementType);\n}\n\nexport function createModule<M extends ModuleSchema>(\n\thost: ReactiveControllerHost,\n\tmoduleDef: ModuleDef<M>,\n\tconfig?: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Plugin types vary\n\t\tplugins?: Plugin<any>[];\n\t\tdebug?: DebugConfig;\n\t\terrorBoundary?: ErrorBoundaryConfig;\n\t\ttickMs?: number;\n\t\tzeroConfig?: boolean;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Facts type varies\n\t\tinitialFacts?: Record<string, any>;\n\t\tstatus?: boolean;\n\t},\n): ModuleController<M> {\n\treturn new ModuleController<M>(host, moduleDef, config);\n}\n\n// ============================================================================\n// Functional Helpers\n// ============================================================================\n\nexport function useDispatch<M extends ModuleSchema = ModuleSchema>(\n\tsystem: SingleModuleSystem<M>,\n): (event: InferEvents<M>) => void {\n\tassertSystem(\"useDispatch\", system);\n\treturn (event: InferEvents<M>) => {\n\t\tsystem.dispatch(event);\n\t};\n}\n\n/**\n * Returns the system's events dispatcher.\n */\nexport function useEvents<M extends ModuleSchema = ModuleSchema>(\n\tsystem: SingleModuleSystem<M>,\n): SingleModuleSystem<M>[\"events\"] {\n\tassertSystem(\"useEvents\", system);\n\treturn system.events;\n}\n\n/**\n * Reactive controller for time-travel state.\n * Triggers host updates when snapshots change or navigation occurs.\n *\n * @example\n * ```typescript\n * class MyElement extends LitElement {\n * private tt = new TimeTravelController(this, system);\n * render() {\n * const { canUndo, undo } = this.tt.value ?? {};\n * return html`<button ?disabled=${!canUndo} @click=${undo}>Undo</button>`;\n * }\n * }\n * ```\n */\nexport class TimeTravelController implements ReactiveController {\n\tvalue: TimeTravelState | null = null;\n\tprivate _unsub?: () => void;\n\n\tconstructor(\n\t\tprivate _host: ReactiveControllerHost,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\t\tprivate _system: SingleModuleSystem<any>,\n\t) {\n\t\tthis._host.addController(this);\n\t}\n\n\thostConnected(): void {\n\t\tthis.value = buildTimeTravelState(this._system);\n\t\tthis._unsub = this._system.onTimeTravelChange(() => {\n\t\t\tthis.value = buildTimeTravelState(this._system);\n\t\t\tthis._host.requestUpdate();\n\t\t});\n\t}\n\n\thostDisconnected(): void {\n\t\tthis._unsub?.();\n\t\tthis._unsub = undefined;\n\t}\n}\n\n/**\n * Functional helper for time-travel state (non-reactive, snapshot).\n * For reactive updates, use TimeTravelController.\n */\n// biome-ignore lint/suspicious/noExplicitAny: System type varies\nexport function useTimeTravel(system: SingleModuleSystem<any>): TimeTravelState | null {\n\tassertSystem(\"useTimeTravel\", system);\n\treturn buildTimeTravelState(system);\n}\n\nexport function getDerived<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tderivationId: string,\n): () => T {\n\treturn () => system.read(derivationId) as T;\n}\n\nexport function getFact<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: System type varies\n\tsystem: SingleModuleSystem<any>,\n\tfactKey: string,\n): () => T | undefined {\n\treturn () => system.facts.$store.get(factKey) as T | undefined;\n}\n\n// ============================================================================\n// Typed Hooks Factory\n// ============================================================================\n\nexport function createTypedHooks<M extends ModuleSchema>(): {\n\tcreateDerived: <K extends keyof InferDerivations<M>>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tderivationId: K,\n\t) => DerivedController<InferDerivations<M>[K]>;\n\tcreateFact: <K extends keyof InferFacts<M>>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tfactKey: K,\n\t) => FactController<InferFacts<M>[K]>;\n\tuseDispatch: (system: SingleModuleSystem<M>) => (event: InferEvents<M>) => void;\n\tuseEvents: (system: SingleModuleSystem<M>) => SingleModuleSystem<M>[\"events\"];\n\tcreateWatch: <K extends string>(\n\t\thost: ReactiveControllerHost,\n\t\tsystem: SingleModuleSystem<M>,\n\t\tkey: K,\n\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t) => WatchController<unknown>;\n} {\n\treturn {\n\t\tcreateDerived: <K extends keyof InferDerivations<M>>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tderivationId: K,\n\t\t) => createDerived<InferDerivations<M>[K]>(host, system, derivationId as string),\n\t\tcreateFact: <K extends keyof InferFacts<M>>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tfactKey: K,\n\t\t) => createFact<InferFacts<M>[K]>(host, system, factKey as string),\n\t\tuseDispatch: (system: SingleModuleSystem<M>) => {\n\t\t\treturn (event: InferEvents<M>) => {\n\t\t\t\tsystem.dispatch(event);\n\t\t\t};\n\t\t},\n\t\tuseEvents: (system: SingleModuleSystem<M>) => system.events,\n\t\tcreateWatch: <K extends string>(\n\t\t\thost: ReactiveControllerHost,\n\t\t\tsystem: SingleModuleSystem<M>,\n\t\t\tkey: K,\n\t\t\tcallback: (newValue: unknown, previousValue: unknown) => void,\n\t\t) => createWatch<unknown>(host, system, key, callback),\n\t};\n}\n\n"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@directive-run/lit",
3
+ "version": "0.1.1",
4
+ "description": "Lit web components adapter for Directive.",
5
+ "license": "MIT",
6
+ "author": "Jason Comes",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/directive-run/directive",
10
+ "directory": "packages/lit"
11
+ },
12
+ "homepage": "https://directive.run",
13
+ "bugs": {
14
+ "url": "https://github.com/directive-run/directive/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.org"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "keywords": [
24
+ "directive",
25
+ "lit",
26
+ "web-components",
27
+ "state-management",
28
+ "reactive",
29
+ "constraint-driven"
30
+ ],
31
+ "sideEffects": false,
32
+ "type": "module",
33
+ "main": "./dist/index.cjs",
34
+ "module": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "require": "./dist/index.cjs",
40
+ "import": "./dist/index.js"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "peerDependencies": {
47
+ "lit": ">=3",
48
+ "@directive-run/core": "0.1.1"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^25.2.0",
52
+ "lit": "^3.1.0",
53
+ "tsup": "^8.3.5",
54
+ "typescript": "^5.7.2",
55
+ "@directive-run/core": "0.1.1"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
+ "test": "vitest run",
61
+ "typecheck": "tsc --noEmit",
62
+ "clean": "rm -rf dist"
63
+ }
64
+ }