@directive-run/lit 0.1.1 → 0.2.0

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/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @directive-run/lit
2
2
 
3
- Lit web components adapter for Directive. Provides reactive controllers and factory functions for reading facts, derivations, and dispatching events.
3
+ [![npm](https://img.shields.io/npm/v/@directive-run/lit?color=%236366f1)](https://www.npmjs.com/package/@directive-run/lit)
4
+ [![downloads](https://img.shields.io/npm/dm/@directive-run/lit)](https://www.npmjs.com/package/@directive-run/lit)
5
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@directive-run/lit)](https://bundlephobia.com/package/@directive-run/lit)
6
+
7
+ Lit reactive controllers for [Directive](https://www.npmjs.com/package/@directive-run/core). Controllers subscribe on `hostConnected` and unsubscribe on `hostDisconnected`, following the Lit `ReactiveController` lifecycle.
4
8
 
5
9
  ## Install
6
10
 
@@ -8,13 +12,46 @@ Lit web components adapter for Directive. Provides reactive controllers and fact
8
12
  npm install @directive-run/core @directive-run/lit
9
13
  ```
10
14
 
11
- ## Usage
15
+ ## Quick Start
16
+
17
+ Define a module in a shared file, then use controllers in any element:
18
+
19
+ ```typescript
20
+ // system.ts
21
+ import { createModule, createSystem, t } from "@directive-run/core";
22
+
23
+ const counter = createModule("counter", {
24
+ schema: {
25
+ facts: { count: t.number() },
26
+ derivations: { doubled: t.number() },
27
+ events: { increment: {}, decrement: {} },
28
+ requirements: {},
29
+ },
30
+ init: (facts) => {
31
+ facts.count = 0;
32
+ },
33
+ derive: {
34
+ doubled: (facts) => facts.count * 2,
35
+ },
36
+ events: {
37
+ increment: (facts) => { facts.count += 1; },
38
+ decrement: (facts) => { facts.count -= 1; },
39
+ },
40
+ });
41
+
42
+ export const system = createSystem({ module: counter });
43
+ system.start();
44
+ ```
12
45
 
13
46
  ```typescript
47
+ // my-counter.ts
14
48
  import { LitElement, html } from "lit";
49
+ import { customElement } from "lit/decorators.js";
15
50
  import { FactController, DerivedController, useEvents } from "@directive-run/lit";
51
+ import { system } from "./system";
16
52
 
17
- class MyCounter extends LitElement {
53
+ @customElement("my-counter")
54
+ export class MyCounter extends LitElement {
18
55
  private count = new FactController<number>(this, system, "count");
19
56
  private doubled = new DerivedController<number>(this, system, "doubled");
20
57
  private events = useEvents(system);
@@ -23,24 +60,91 @@ class MyCounter extends LitElement {
23
60
  return html`
24
61
  <p>Count: ${this.count.value} (doubled: ${this.doubled.value})</p>
25
62
  <button @click=${() => this.events.increment()}>+</button>
63
+ <button @click=${() => this.events.decrement()}>&minus;</button>
26
64
  `;
27
65
  }
28
66
  }
29
67
  ```
30
68
 
31
- ## Exports
69
+ ## DirectiveSelectorController
70
+
71
+ Auto-tracking selector controller. Subscribes only to the keys your selector reads:
72
+
73
+ ```typescript
74
+ import { LitElement, html } from "lit";
75
+ import { DirectiveSelectorController } from "@directive-run/lit";
76
+ import { system } from "./system";
77
+
78
+ class MySummary extends LitElement {
79
+ private label = new DirectiveSelectorController(
80
+ this, system, (state) => state.count > 10 ? "High" : "Low"
81
+ );
82
+
83
+ render() {
84
+ return html`<span>${this.label.value}</span>`;
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## API Reference
90
+
91
+ ### Controllers
92
+
93
+ | Controller | `.value` Type | Description |
94
+ |------------|--------------|-------------|
95
+ | `FactController<T>(host, system, key)` | `T \| undefined` | Subscribe to a single fact |
96
+ | `DerivedController<T>(host, system, key)` | `T` | Subscribe to a single derivation |
97
+ | `DerivedController<T>(host, system, [keys])` | `Record<string, unknown>` | Subscribe to multiple derivations |
98
+ | `DirectiveSelectorController<R>(host, system, fn)` | `R` | Auto-tracking selector |
99
+ | `WatchController<T>(host, system, key, cb)` | &ndash; | Side-effect on change |
100
+ | `InspectController(host, system)` | `InspectState` | Consolidated system state |
101
+ | `RequirementStatusController(host, plugin, type)` | `RequirementTypeStatus` | Requirement loading/error |
102
+ | `ExplainController(host, system, reqId)` | `string \| null` | Requirement explanation |
103
+ | `ConstraintStatusController(host, system)` | `ConstraintInfo[]` | All constraint states |
104
+ | `OptimisticUpdateController(host, system)` | `{ isPending, error }` | Optimistic mutation with `.mutate()` and `.rollback()` |
105
+ | `TimeTravelController(host, system)` | `TimeTravelState \| null` | Undo/redo navigation |
106
+ | `SystemController(host, module)` | &ndash; | Manages system lifecycle (`.system` accessor) |
107
+ | `ModuleController(host, module)` | &ndash; | All-in-one: creates system, subscribes to all facts/derivations |
32
108
 
33
- **Controllers:** `FactController`, `DerivedController`, `InspectController`, `RequirementStatusController`, `DirectiveSelectorController`, `WatchController`, `ExplainController`, `ConstraintStatusController`, `OptimisticUpdateController`, `SystemController`, `ModuleController`, `TimeTravelController`
109
+ ### Factory Functions
34
110
 
35
- **Factories:** `createFact`, `createDerived`, `createInspect`, `createRequirementStatus`, `createWatch`, `createDirectiveSelector`, `createExplain`, `createConstraintStatus`, `createOptimisticUpdate`, `createModule`, `useDispatch`, `useEvents`, `useTimeTravel`, `getDerived`, `getFact`, `createTypedHooks`, `shallowEqual`
111
+ Shorthand for creating controllers:
112
+
113
+ | Factory | Creates |
114
+ |---------|---------|
115
+ | `createFact(host, system, key)` | `FactController` |
116
+ | `createDerived(host, system, key)` | `DerivedController` |
117
+ | `createDirectiveSelector(host, system, fn)` | `DirectiveSelectorController` |
118
+ | `createWatch(host, system, key, cb)` | `WatchController` |
119
+ | `createInspect(host, system)` | `InspectController` |
120
+ | `createRequirementStatus(host, plugin, type)` | `RequirementStatusController` |
121
+ | `createExplain(host, system, reqId)` | `ExplainController` |
122
+ | `createConstraintStatus(host, system)` | `ConstraintStatusController` |
123
+ | `createOptimisticUpdate(host, system)` | `OptimisticUpdateController` |
124
+ | `createModule(host, module)` | `ModuleController` |
125
+
126
+ ### Functional Helpers
127
+
128
+ | Helper | Return Type | Description |
129
+ |--------|------------|-------------|
130
+ | `useDispatch(system)` | `(event) => void` | Dispatch function (non-reactive) |
131
+ | `useEvents(system)` | `Events` | Events dispatcher (non-reactive) |
132
+ | `useTimeTravel(system)` | `TimeTravelState \| null` | Snapshot time-travel state (non-reactive) |
133
+ | `getDerived(system, key)` | `() => T` | Getter function for a derivation |
134
+ | `getFact(system, key)` | `() => T` | Getter function for a fact |
135
+ | `createTypedHooks()` | `{ createDerived, createFact, ... }` | Factory for pre-typed controllers |
136
+ | `shallowEqual` | `(a, b) => boolean` | Shallow equality helper |
36
137
 
37
138
  ## Peer Dependencies
38
139
 
39
140
  - `lit >= 3`
40
141
  - `@directive-run/core`
41
142
 
143
+ ## Documentation
144
+
145
+ - [Lit Adapter Guide](https://directive.run/docs/adapters/lit)
146
+ - [API Reference](https://directive.run/docs/api)
147
+
42
148
  ## License
43
149
 
44
150
  MIT
45
-
46
- [Full documentation](https://directive.run/docs)
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var core=require('@directive-run/core'),adapterUtils=require('@directive-run/core/adapter-utils');var 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:
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),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},m=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},f=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},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
2
  1. Accessed before hostConnected (e.g., in a class field initializer)
3
3
  2. Accessed after hostDisconnected (system was destroyed)
4
- Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?core.createSystem({module:this.options}):core.createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},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
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 m(s,e,t)}function A(s,e,t){return new f(s,e,t)}function O(s,e,t,i){return new b(s,e,t,i)}function B(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=f;exports.DerivedController=d;exports.DirectiveSelectorController=p;exports.ExplainController=m;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=B;exports.createOptimisticUpdate=O;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
5
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","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,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,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACpB,CAIU,aAAA,EAAsB,CAC/B,IAAA,CAAK,IAAA,CAAK,aAAA,GACX,CACD,CAAA,CAYaE,CAAAA,CAAN,c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,CAAK,KAAA,CAAQA,iCAAAA,CAAqB,IAAA,CAAK,OAAO,CAAA,CAC9C,IAAA,CAAK,KAAA,CAAM,aAAA,GACZ,CAAC,EACF,CAEA,gBAAA,EAAyB,CACxB,IAAA,CAAK,MAAA,IAAS,CACd,IAAA,CAAK,OAAS,OACf,CACD,EAOO,SAASC,EAAcpE,CAAAA,CAAyD,CACtF,OAAA8D,yBAAAA,CAAa,gBAAiB9D,CAAM,CAAA,CAC7BmE,iCAAAA,CAAqBnE,CAAM,CACnC,CAEO,SAASgD,CAAAA,CAEfhD,CAAAA,CACAuD,CAAAA,CACU,CACV,OAAO,IAAMvD,EAAO,IAAA,CAAKuD,CAAY,CACtC,CAEO,SAASc,CAAAA,CAEfrE,CAAAA,CACAM,CAAAA,CACsB,CACtB,OAAO,IAAMN,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIM,CAAO,CAC7C,CAMO,SAASgE,CAAAA,EAmBd,CACD,OAAO,CACN,cAAe,CACdvE,CAAAA,CACAC,CAAAA,CACAuD,CAAAA,GACIL,EAAsCnD,CAAAA,CAAMC,CAAAA,CAAQuD,CAAsB,CAAA,CAC/E,UAAA,CAAY,CACXxD,CAAAA,CACAC,CAAAA,CACAM,IACI6C,CAAAA,CAA6BpD,CAAAA,CAAMC,CAAAA,CAAQM,CAAiB,EACjE,WAAA,CAAcN,CAAAA,EACLiD,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"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","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,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,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACpB,CAIU,aAAA,EAAsB,CAC/B,IAAA,CAAK,IAAA,CAAK,aAAA,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,CAAQA,iCAAAA,CAAqB,IAAA,CAAK,OAAO,CAAA,CAC9C,IAAA,CAAK,KAAA,CAAM,aAAA,GACZ,CAAC,EACF,CAEA,gBAAA,EAAyB,CACxB,IAAA,CAAK,MAAA,IAAS,CACd,IAAA,CAAK,OAAS,OACf,CACD,EAOO,SAASC,EAAcnE,CAAAA,CAAyD,CACtF,OAAA6D,yBAAAA,CAAa,gBAAiB7D,CAAM,CAAA,CAC7BkE,iCAAAA,CAAqBlE,CAAM,CACnC,CAEO,SAAS+C,CAAAA,CAEf/C,CAAAA,CACAsD,CAAAA,CACU,CACV,OAAO,IAAMtD,EAAO,IAAA,CAAKsD,CAAY,CACtC,CAEO,SAASc,CAAAA,CAEfpE,CAAAA,CACAM,CAAAA,CACsB,CACtB,OAAO,IAAMN,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIM,CAAO,CAC7C,CAMO,SAAS+D,CAAAA,EAmBd,CACD,OAAO,CACN,cAAe,CACdtE,CAAAA,CACAC,CAAAA,CACAsD,CAAAA,GACIL,EAAsClD,CAAAA,CAAMC,CAAAA,CAAQsD,CAAsB,CAAA,CAC/E,UAAA,CAAY,CACXvD,CAAAA,CACAC,CAAAA,CACAM,IACI4C,CAAAA,CAA6BnD,CAAAA,CAAMC,CAAAA,CAAQM,CAAiB,EACjE,WAAA,CAAcN,CAAAA,EACLgD,CAAAA,EAA0B,CACjChD,EAAO,QAAA,CAASgD,CAAK,EACtB,CAAA,CAED,UAAYhD,CAAAA,EAAkCA,CAAAA,CAAO,MAAA,CACrD,WAAA,CAAa,CACZD,CAAAA,CACAC,CAAAA,CACAE,CAAAA,CACAyB,CAAAA,GACI0B,EAAqBtD,CAAAA,CAAMC,CAAAA,CAAQE,CAAAA,CAAKyB,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\tsuper(host, system);\n\t\tthis.key = key;\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/dist/index.d.cts CHANGED
@@ -120,14 +120,6 @@ declare class WatchController<T> extends DirectiveController {
120
120
  private callback;
121
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
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
123
  protected subscribe(): void;
132
124
  }
133
125
  /**
package/dist/index.d.ts CHANGED
@@ -120,14 +120,6 @@ declare class WatchController<T> extends DirectiveController {
120
120
  private callback;
121
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
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
123
  protected subscribe(): void;
132
124
  }
133
125
  /**
package/dist/index.js CHANGED
@@ -1,5 +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:
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),this.key=i,this.callback=n;}subscribe(){this.unsubscribe=this.system.watch(this.key,this.callback);}},m=class extends r{requirementId;value;unsubSettled;constructor(e,t,i){super(e,t),this.requirementId=i,this.value=t.explain(i);}subscribe(){this.value=this.system.explain(this.requirementId);let e=()=>{this.value=this.system.explain(this.requirementId),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},f=class extends r{constraintId;value;unsubSettled;constructor(e,t,i){super(e,t),this.constraintId=i,this.value=this.getVal();}getVal(){let e=this.system.inspect();return this.constraintId?e.constraints.find(t=>t.id===this.constraintId)??null:e.constraints}subscribe(){this.value=this.getVal();let e=()=>{this.value=this.getVal(),this.requestUpdate();};this.unsubscribe=this.system.facts.$store.subscribeAll(e),this.unsubSettled=this.system.onSettledChange(e);}hostDisconnected(){this.unsubSettled?.(),super.hostDisconnected();}},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
2
  1. Accessed before hostConnected (e.g., in a class field initializer)
3
3
  2. Accessed after hostDisconnected (system was destroyed)
4
- Solution: Access system only in lifecycle methods (connectedCallback, render) or after the element is connected to the DOM.`);return this._system}hostConnected(){let t="id"in this.options&&"schema"in this.options?createSystem({module:this.options}):createSystem(this.options);this._system=t,this._system.start();}hostDisconnected(){this._system?.destroy(),this._system=null;}},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
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 m(s,e,t)}function A(s,e,t){return new f(s,e,t)}function O(s,e,t,i){return new b(s,e,t,i)}function B(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{f as ConstraintStatusController,d as DerivedController,p as DirectiveSelectorController,m 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,B as createModule,O 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
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","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,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACpB,CAIU,aAAA,EAAsB,CAC/B,IAAA,CAAK,IAAA,CAAK,aAAA,GACX,CACD,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACrD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACCC,CAAAA,CAEAC,CAAAA,CACAE,EACC,CACD,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,OAAA,CAAU,KAAA,CAAM,QAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA,CAAO,IAAA,CAAK,OAA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BAAiB9D,CAAM,CAAA,CAC7BmE,oBAAAA,CAAqBnE,CAAM,CACnC,CAEO,SAASgD,CAAAA,CAEfhD,CAAAA,CACAuD,CAAAA,CACU,CACV,OAAO,IAAMvD,EAAO,IAAA,CAAKuD,CAAY,CACtC,CAEO,SAASc,CAAAA,CAEfrE,CAAAA,CACAM,CAAAA,CACsB,CACtB,OAAO,IAAMN,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIM,CAAO,CAC7C,CAMO,SAASgE,CAAAA,EAmBd,CACD,OAAO,CACN,cAAe,CACdvE,CAAAA,CACAC,CAAAA,CACAuD,CAAAA,GACIL,EAAsCnD,CAAAA,CAAMC,CAAAA,CAAQuD,CAAsB,CAAA,CAC/E,UAAA,CAAY,CACXxD,CAAAA,CACAC,CAAAA,CACAM,IACI6C,CAAAA,CAA6BpD,CAAAA,CAAMC,CAAAA,CAAQM,CAAiB,EACjE,WAAA,CAAcN,CAAAA,EACLiD,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.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"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["directiveContext","DirectiveController","host","system","DerivedController","key","result","id","FactController","factKey","InspectController","options","computeInspectState","update","throttled","cleanup","createThrottle","RequirementStatusController","statusPlugin","type","DirectiveSelectorController","selector","equalityFn","defaultEquality","initial","runTrackedSelector","unsub","onUpdate","depsChanged","WatchController","callback","ExplainController","requirementId","ConstraintStatusController","constraintId","inspection","c","OptimisticUpdateController","requirementType","updateFn","status","SystemController","createSystem","ModuleController","moduleDef","config","allPlugins","sp","createRequirementStatusPlugin","derivationKeys","getDerived","event","createDerived","createFact","createInspect","createRequirementStatus","createWatch","derivationId","createDirectiveSelector","createExplain","createConstraintStatus","createOptimisticUpdate","createModule","useDispatch","assertSystem","useEvents","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,IAAc,CACnB,IAAA,CAAK,WAAA,CAAc,OACpB,CAIU,aAAA,EAAsB,CAC/B,IAAA,CAAK,IAAA,CAAK,aAAA,GACX,CACD,CAAA,CAYaE,CAAAA,CAAN,cAAmCH,CAAoB,CACrD,IAAA,CACA,OAAA,CACR,KAAA,CAEA,WAAA,CACCC,CAAAA,CAEAC,CAAAA,CACAE,EACC,CACD,KAAA,CAAMH,CAAAA,CAAMC,CAAM,CAAA,CAClB,IAAA,CAAK,OAAA,CAAU,KAAA,CAAM,QAAQE,CAAG,CAAA,CAChC,IAAA,CAAK,IAAA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BkE,oBAAAA,CAAqBlE,CAAM,CACnC,CAEO,SAAS+C,CAAAA,CAEf/C,CAAAA,CACAsD,CAAAA,CACU,CACV,OAAO,IAAMtD,EAAO,IAAA,CAAKsD,CAAY,CACtC,CAEO,SAASc,CAAAA,CAEfpE,CAAAA,CACAM,CAAAA,CACsB,CACtB,OAAO,IAAMN,CAAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAIM,CAAO,CAC7C,CAMO,SAAS+D,CAAAA,EAmBd,CACD,OAAO,CACN,cAAe,CACdtE,CAAAA,CACAC,CAAAA,CACAsD,CAAAA,GACIL,EAAsClD,CAAAA,CAAMC,CAAAA,CAAQsD,CAAsB,CAAA,CAC/E,UAAA,CAAY,CACXvD,CAAAA,CACAC,CAAAA,CACAM,IACI4C,CAAAA,CAA6BnD,CAAAA,CAAMC,CAAAA,CAAQM,CAAiB,EACjE,WAAA,CAAcN,CAAAA,EACLgD,CAAAA,EAA0B,CACjChD,EAAO,QAAA,CAASgD,CAAK,EACtB,CAAA,CAED,UAAYhD,CAAAA,EAAkCA,CAAAA,CAAO,MAAA,CACrD,WAAA,CAAa,CACZD,CAAAA,CACAC,CAAAA,CACAE,CAAAA,CACAyB,CAAAA,GACI0B,EAAqBtD,CAAAA,CAAMC,CAAAA,CAAQE,CAAAA,CAAKyB,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\tsuper(host, system);\n\t\tthis.key = key;\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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directive-run/lit",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Lit web components adapter for Directive.",
5
5
  "license": "MIT",
6
6
  "author": "Jason Comes",
@@ -44,15 +44,15 @@
44
44
  "dist"
45
45
  ],
46
46
  "peerDependencies": {
47
- "lit": ">=3",
48
- "@directive-run/core": "0.1.1"
47
+ "@directive-run/core": "*",
48
+ "lit": ">=3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^25.2.0",
52
52
  "lit": "^3.1.0",
53
53
  "tsup": "^8.3.5",
54
54
  "typescript": "^5.7.2",
55
- "@directive-run/core": "0.1.1"
55
+ "@directive-run/core": "0.2.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsup",