@vielzeug/ledger 1.1.5 → 2.0.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/dist/_dev.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=!globalThis.__LEDGER_PROD__;function t(t){e&&console.warn(`[@vielzeug/ledger] ${t}`)}exports.warn=t;
1
+ function e(e){}exports.warn=e;
2
2
  //# sourceMappingURL=_dev.cjs.map
package/dist/_dev.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAAA,IAAM,EAAQ,CAAE,WAA6C,gBAG7D,SAAgB,EAAK,EAAmB,CAClC,GAAO,QAAQ,KAAK,sBAAsB,GAAK,CACrD"}
1
+ {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAGA,SAAgB,EAAK,EAAmB,CAExC"}
package/dist/_dev.js CHANGED
@@ -1,9 +1,6 @@
1
1
  //#region src/_dev.ts
2
- var e = !globalThis.__LEDGER_PROD__;
3
- function t(t) {
4
- e && console.warn(`[@vielzeug/ledger] ${t}`);
5
- }
2
+ function e(e) {}
6
3
  //#endregion
7
- export { t as warn };
4
+ export { e as warn };
8
5
 
9
6
  //# sourceMappingURL=_dev.js.map
package/dist/_dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":";AAAA,IAAM,IAAQ,CAAE,WAA6C;AAG7D,SAAgB,EAAK,GAAmB;CACtC,AAAI,KAAO,QAAQ,KAAK,sBAAsB,GAAK;AACrD"}
1
+ {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":";AAGA,SAAgB,EAAK,GAAmB,CAExC"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,CAClD,CAEA,OAAO,GAAG,EAAkC,CAC1C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAyC,CAAY,CAAC,EAGzC,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAkC,CAC1C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAyC,CAAY,CAAC,EAGzC,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAoB,MAAM;CACrC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,IAAI,OAAO,MACvB,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;CAEA,OAAO,GAAG,GAAkC;EAC1C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAAyC,EAAY,CAAC,GAGzC,IAAb,cAA0C,EAAY,CAAC,GAG1C,IAAb,cAAyC,EAAY,CAAC"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAoB,MAAM;CACrC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;CAEA,OAAO,GAAG,GAAkC;EAC1C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAAyC,EAAY,CAAC,GAGzC,IAAb,cAA0C,EAAY,CAAC,GAG1C,IAAb,cAAyC,EAAY,CAAC"}
package/dist/ledger.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=null,o=()=>a,s=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},c=class extends s{},l=class extends s{},u=0,d=()=>++u,f=()=>u,p={scheduling:{activeDirty:`a`,batchDepth:0,dirtyWithEffectSubsA:new Set,dirtyWithEffectSubsB:new Set,pendingSubscribers:new Set},scopeCleanups:null,tracking:null},m=null,h=()=>m===null?p:m.get(),g=()=>h().scheduling,_=()=>m!==null,v=()=>h().tracking,y=(e,t)=>{if(m!==null){let n=m.get();return m.run({...n,tracking:e},t)}let n=p;p={...p,tracking:e};try{return t()}finally{p=n}},b=()=>h().scopeCleanups,x=e=>{let t=v();t?.kind===`effect`?t.cleanups.push(e):b()?.push(e)},S=e=>{let t=v();if(t!==null){if(t.sourceObserver?.(e),t.kind===`computed`)t.depCollector.push({source:e,version:e.version});else if(t.kind===`effect`){let n=t.effect;e.addEffectSub(n),t.subscriptions.add(()=>e.removeEffectSub(n)),t.deps.set(e,e.version)}}},C=e=>e instanceof Error?e:Error(`Non-Error thrown: ${String(e)}`),w=e=>{let t=[];for(let n of e)try{n()}catch(e){t.push(C(e))}return t},T=(e,t)=>{let n=w(e);if(n.length===1)throw n[0];if(n.length>0)throw AggregateError(n,t)},E=!globalThis.__RIPPLE_PROD__;function D(e){E&&console.warn(`[@vielzeug/ripple] ${e}`)}var O=!1,k=0,A=[],j=e=>e.activeDirty===`a`?e.dirtyWithEffectSubsA:e.dirtyWithEffectSubsB,M=(e,t)=>{let n=++k;for(let n of t.effectSubs())e.pendingSubscribers.add(n);for(let e of t.computedSubs())A.push(e);try{for(;A.length>0;){let t=A.pop();if(t.lastPropEpoch_!==n&&(t.lastPropEpoch_=n,t.markDirty())){t.effectSubs().size>0&&j(e).add(t);for(let e of t.computedSubs())A.push(e)}}}finally{A.length=0}},N=e=>{for(;j(e).size>0;){let t=j(e);e.activeDirty=e.activeDirty===`a`?`b`:`a`,j(e).clear();for(let n of t)if(n.hasSubscribers()&&n.refreshIfDirty()){for(let t of n.effectSubs())e.pendingSubscribers.add(t);for(let t of n.computedSubs())t.markDirty()&&t.effectSubs().size>0&&j(e).add(t)}t.clear()}},P=e=>{let t=0;for(;e.pendingSubscribers.size>0||j(e).size>0;){if(++t>100)throw new l(`infinite flush loop (> 100 iterations)`);if(j(e).size>0&&N(e),e.pendingSubscribers.size===0)continue;let n=[...e.pendingSubscribers];e.pendingSubscribers.clear(),T(n,`subscriber errors`)}},F=globalThis.process?.versions!=null,I=e=>{if(!e.hasSubscribers())return;!O&&F&&!_()&&(O=!0,D(`Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.`));let t=g();M(t,e),t.batchDepth===0&&P(t)},L=class{fn_;disposed_=!1;constructor(e){this.fn_=e}get disposed(){return this.disposed_}dispose(){if(this.disposed_)return;this.disposed_=!0;let e=this.fn_;this.fn_=null,e()}[Symbol.dispose](){this.dispose()}},R=Symbol(`ripple.is-signal`),z=Symbol(`ripple.is-computed`),B=Symbol(`ripple.uninitialized`),V=new FinalizationRegistry(({key:e,map:t})=>{t.delete(e)}),H=class{version=0;name;[R]=!0;computedSubs_=new Map;effectSubs_=new Set;constructor(e){this.name=e}addComputedSub(e){let t=new WeakRef(e);this.computedSubs_.set(e,t),V.register(e,{key:e,map:this.computedSubs_},t)}removeComputedSub(e){let t=this.computedSubs_.get(e);t!==void 0&&(this.computedSubs_.delete(e),V.unregister(t))}addEffectSub(e){this.effectSubs_.add(e)}removeEffectSub(e){this.effectSubs_.delete(e)}clearSubscribers(){for(let e of this.computedSubs_.values())V.unregister(e);this.computedSubs_.clear(),this.effectSubs_.clear()}hasSubscribers(){if(this.effectSubs_.size>0)return!0;for(let e of this.computedSubs_.values())if(e.deref()!==void 0)return!0;return!1}*computedSubs(){for(let[e,t]of this.computedSubs_){let n=t.deref();n===void 0?(this.computedSubs_.delete(e),V.unregister(t)):yield n}}effectSubs(){return this.effectSubs_}},U=class extends H{[z]=!0;lastPropEpoch_=0},W=class extends U{value_;dirty_;computing_;disposed_;deps_;compute_;equals_;maxRevision_;constructor(e,t){let{equals:n,name:r}=t??{};super(r),this.value_=B,this.dirty_=!0,this.computing_=!1,this.disposed_=!1,this.deps_=[],this.maxRevision_=-1,this.compute_=e,this.equals_=n===void 0?Object.is:(e,t)=>n(e,t)}markDirty(){return this.disposed_||this.dirty_?!1:(this.dirty_=!0,!0)}refreshIfDirty(){if(!this.dirty_)return!1;if(f()<=this.maxRevision_)return this.dirty_=!1,!1;if(this.deps_.length>0){let e=!0;for(let t of this.deps_){let n=t.source;if(`refreshIfDirty`in n&&n.refreshIfDirty(),n.version!==t.version){e=!1;break}}if(e)return this.dirty_=!1,this.maxRevision_=f(),!1}return this.recompute()}runCompute(e){try{return y({computed:this,depCollector:e,kind:`computed`},this.compute_)}catch(e){throw C(e)}}recompute(){if(this.computing_)throw new c(`computed cycle detected${this.name?` "${this.name}"`:``}`);this.computing_=!0;try{let e=[];o()?.compute?.({name:this.name});let t=this.runCompute(e);return this.dirty_=!1,this.maxRevision_=f(),this.updateDeps(e),this.value_===B||!this.equals_(this.value_,t)?(this.value_=t,this.version++,!0):!1}finally{this.computing_=!1}}updateDeps(e){let t=this.deps_;if(t.length===e.length&&t.every((t,n)=>t.source===e[n].source)){for(let n=0;n<e.length;n++)t[n].version=e[n].version;return}let n=new Set(t.map(e=>e.source)),r=new Set(e.map(e=>e.source));for(let e of t)r.has(e.source)||e.source.removeComputedSub(this);for(let t of e)n.has(t.source)||t.source.addComputedSub(this);this.deps_=e}get value(){return this.disposed_?this.value_===B?void 0:this.value_:(this.refreshIfDirty(),S(this),this.value_)}peek(){return this.disposed_?this.value_===B?void 0:this.value_:(this.refreshIfDirty(),this.value_)}subscribe=e=>{if(this.disposed_){let e=new L(()=>{});return e.dispose(),e}return this.refreshIfDirty(),this.addEffectSub(e),new L(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){if(!this.disposed_){this.disposed_=!0;for(let e of this.deps_)e.source.removeComputedSub(this);this.deps_=[],this.clearSubscribers(),o()?.dispose?.({kind:`computed`,name:this.name})}}[Symbol.dispose](){this.dispose()}},G=(e,t)=>{let n=new W(e,t);return x(()=>n.dispose()),n},K=class extends H{value_;equals_;disposed_;constructor(e,t,n){super(n),this.value_=e,this.equals_=t??Object.is,this.disposed_=!1}get value(){return this.disposed_||S(this),this.value_}set value(e){if(this.disposed_||this.equals_(this.value_,e))return;let t=this.value_;this.value_=e,this.version=d(),o()?.write?.({name:this.name,newValue:e,oldValue:t}),I(this)}peek(){return this.value_}subscribe=e=>{if(this.disposed_){let e=new L(()=>{});return e.dispose(),e}return this.addEffectSub(e),new L(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){this.disposed_||(this.disposed_=!0,this.clearSubscribers(),o()?.dispose?.({kind:`signal`,name:this.name}))}[Symbol.dispose](){this.dispose()}},q=(e,t)=>new K(e,t?.equals,t?.name),J=!globalThis.__LEDGER_PROD__;function Y(e){J&&console.warn(`[@vielzeug/ledger] ${e}`)}function X(e){return e instanceof Error?e.message:String(e)}function Z(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function Q(e={}){let{maxHistory:t=100,onRollbackError:a}=e;t<1&&Y(`maxHistory must be >= 1; history tracking is disabled for this ledger.`);let o=q([],{name:`ledger:undoStack`}),s=q([],{name:`ledger:redoStack`}),c=q(0,{name:`ledger:pending`}),l=q(!1,{name:`ledger:processing`}),u=G(()=>o.value.length>0,{name:`ledger:canUndo`}),d=G(()=>s.value.length>0,{name:`ledger:canRedo`}),f=G(()=>o.value.length,{name:`ledger:historySize`}),p=G(()=>l.value,{name:`ledger:isProcessing`}),m=G(()=>c.value,{name:`ledger:pendingCount`}),h=G(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=[o,s,c,l,u,d,f,p,m,h],_=!1,v=Promise.resolve(),y=new AbortController;function b(e){return e?AbortSignal.any([e,y.signal]):y.signal}function x(e,t){if(_)return Promise.reject(new n(`Cannot call ${e}() on a disposed ledger.`));c.value++;let r=v.then(t).finally(()=>{_||c.value--});return v=r.catch(()=>{}),r}async function S(e){l.value=!0;try{await e()}finally{_||(l.value=!1)}}async function C(e,n){await S(async()=>{try{await e.execute(n)}catch(e){throw new r(X(e),{cause:e})}if(_)return;let i=[...o.value,e];i.length>t&&i.shift(),o.value=i,s.value=[]})}async function w(e){let t=o.value;if(t.length===0)return;let n=t[t.length-1];await S(async()=>{if(n.rollback)try{await n.rollback(e)}catch(e){Y(`rollback() threw for "${n.meta.label??`(unlabelled)`}". Stack position unchanged.`),a?.(new i(X(e),{cause:e}),n.meta);return}_||(o.value=t.slice(0,-1),s.value=[...s.value,n])})}async function T(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await S(async()=>{try{await n.execute(e)}catch(e){throw new r(X(e),{cause:e})}_||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function E(){return x(`clear`,async()=>{_||(o.value=[],s.value=[])})}function D(){_=!0,y.abort(),o.value=[],s.value=[];for(let e of g)e.dispose()}return{canRedo:d,canUndo:u,clear:E,get disposalSignal(){return y.signal},dispose:D,get disposed(){return _},do(e,t){return x(`do`,()=>C(Z(e),b(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return x(`redo`,()=>T(b(e?.signal)))},[Symbol.dispose](){D()},undo(e){return x(`undo`,()=>w(b(e?.signal)))}}}exports.LedgerDisposedError=n,exports.LedgerError=t,exports.LedgerExecutionError=r,exports.LedgerRollbackError=i,exports.compose=e,exports.createLedger=Q;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},o=class extends a{},s=class extends a{},c=class extends a{},l=Symbol(`ripple.reactive`),u=Symbol(`ripple.signal`),d=Symbol(`ripple.computed`),f=100,p=Symbol(`ripple.unset`),m=class{[l]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.peek();let t={dependencies:new Set,onDependencyChanged:()=>this.runtime.enqueueListener(e)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},h=class extends m{[u]=!0;current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({kind:`write`,name:this.name,next:e,previous:t}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}},g=class extends m{[d]=!0;dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=p;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.refresh(),this.runtime.track(this),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){this.disposed||(this.dirty||=!0,this.dependents.size>0&&this.refresh()&&this.notify())}dispose(){this.disposed||(this.disposed=!0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing)throw new o(`computed cycle detected${this.name===void 0?``:` "${this.name}"`}`);this.computing=!0,this.runtime.emit({kind:`compute`,name:this.name});try{let e=this.runtime.collect(this,this.derive),t=this.current===p||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},_=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}run(e){if(this.isDisposed)throw new s(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.name,node:`scope`})}}[Symbol.dispose](){this.dispose()}},v=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;owner;scheduled=!1;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}onDependencyChanged(){if(!this.isDisposed){if(this.options?.scheduler===`microtask`){if(this.scheduled)return;this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.isDisposed||this.runtime.enqueue(this)});return}this.runtime.enqueue(this)}}run(){if(this.isDisposed)return;this.owner?.dispose(),this.owner=void 0,this.runCleanup(),this.runtime.emit({kind:`effect`,name:this.options?.name});let e=new _(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.owner=e,this.cleanup=typeof t==`function`?t:void 0}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.owner?.dispose(),this.owner=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.options?.name,node:`effect`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},y=class{activeEffectScope;activeObserver;activeScope;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;observer;onError;constructor(e){this.observer=e?.observer,this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new _(this,`runtime`),this.activeScope=this.rootScope}signal=(e,t)=>new h(this,e,t);computed=(e,t)=>{let n=new g(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{let n=new v(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{let t=new _(this,e);return this.activeScope.owned.add(t),t};batch=e=>this.propagate(e);untrack=e=>this.withObserver(void 0,e);dispose(){this.rootScope.dispose()}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,!1)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){try{this.observer?.(e)}catch(t){this.report(t,{kind:`observer`,name:e.name})}}report(e,t){try{this.onError(e,t)}catch(e){queueMicrotask(()=>{throw e})}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>f)throw new c(`infinite reactive flush (>${f} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},b=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o=new AbortController,s,c=!1,l=()=>{a.value,s?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,o;try{o=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;s=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(o,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!c&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!c&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},u=e.effect(()=>(l(),()=>s?.abort()),{name:r?.name});return u.disposalSignal.addEventListener(`abort`,()=>{c=!0,o.abort()},{once:!0}),{get disposalSignal(){return o.signal},dispose:()=>u.dispose(),get disposed(){return c},get name(){return i.name},peek:()=>i.peek(),reload:()=>{c||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}}},x=e=>(t,n)=>{let r=e.signal(t,{name:n?.name});return{get name(){return r.name},peek:()=>r.peek(),set:e=>{r.value=e},subscribe:e=>r.subscribe(e),update:e=>{r.value=e(r.peek())},get value(){return r.value}}},S=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s,c=!1,l=e.effect(()=>{let e=i();if(o){o=!1,s=e,r?.immediate&&n(e,void 0),c=r?.once===!0&&r.immediate===!0;return}if(a(s,e))return;let t=s;s=e,n(e,t),r?.once&&l.dispose()},{name:r?.name});return c&&l.dispose(),l},C=(e=>{let t=new y(e),n=b(t),r=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,createStore:r,dispose:()=>t.dispose(),effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal,T=C.computed;C.effect,C.batch,C.createScope,C.createStore,C.resource,C.untrack,C.watch;function E(e){return e instanceof Error?e.message:String(e)}function D(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function O(e={}){let{maxHistory:t=100,onRollbackError:a}=e,o=w([],{name:`ledger:undoStack`}),s=w([],{name:`ledger:redoStack`}),c=w(0,{name:`ledger:pending`}),l=w(!1,{name:`ledger:processing`}),u=T(()=>o.value.length>0,{name:`ledger:canUndo`}),d=T(()=>s.value.length>0,{name:`ledger:canRedo`}),f=T(()=>o.value.length,{name:`ledger:historySize`}),p=T(()=>l.value,{name:`ledger:isProcessing`}),m=T(()=>c.value,{name:`ledger:pendingCount`}),h=T(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=!1,_=Promise.resolve(),v=new AbortController;function y(e){return e?AbortSignal.any([e,v.signal]):v.signal}function b(e,t){if(g)return Promise.reject(new n(`Cannot call ${e}() on a disposed ledger.`));c.value++;let r=_.then(t).finally(()=>{g||c.value--});return _=r.catch(()=>{}),r}async function x(e){l.value=!0;try{await e()}finally{g||(l.value=!1)}}async function S(e,n){await x(async()=>{try{await e.execute(n)}catch(e){throw new r(E(e),{cause:e})}if(g)return;let i=[...o.value,e];i.length>t&&i.shift(),o.value=i,s.value=[]})}async function C(e){let t=o.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{if(n.rollback)try{await n.rollback(e)}catch(e){`${n.meta.label??`(unlabelled)`}`,a?.(new i(E(e),{cause:e}),n.meta);return}g||(o.value=t.slice(0,-1),s.value=[...s.value,n])})}async function O(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{try{await n.execute(e)}catch(e){throw new r(E(e),{cause:e})}g||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function k(){return b(`clear`,async()=>{g||(o.value=[],s.value=[])})}function A(){g=!0,v.abort(),o.value=[],s.value=[]}return{canRedo:d,canUndo:u,clear:k,get disposalSignal(){return v.signal},dispose:A,get disposed(){return g},do(e,t){return b(`do`,()=>S(D(e),y(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return b(`redo`,()=>O(y(e?.signal)))},[Symbol.dispose](){A()},undo(e){return b(`undo`,()=>C(y(e?.signal)))}}}exports.LedgerDisposedError=n,exports.LedgerError=t,exports.LedgerExecutionError=r,exports.LedgerRollbackError=i,exports.compose=e,exports.createLedger=O;
2
2
  //# sourceMappingURL=ledger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.cjs","names":["e","t","n","e","t","n","r","i","a","o","e","t","n","r","i","a","o","s","c","l","u","d","f","p","m","e","t","n","r","e","t","o","s","u","d","t","e","i","n","r","e","t","n","r","t","e","l","c","i","o","t","n","a","s","e","r","a","n","t","e","r","i"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/devtools-hook.js","../../ripple/dist/errors.js","../../ripple/dist/tracking.js","../../ripple/dist/_error-utils.js","../../ripple/dist/_dev.js","../../ripple/dist/scheduling.js","../../ripple/dist/subscription.js","../../ripple/dist/symbols.js","../../ripple/dist/reactive-base.js","../../ripple/dist/computed.js","../../ripple/dist/signal.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/devtools-hook.ts\nvar e = null, t = () => e, n = (t) => {\n\te = t;\n};\n//#endregion\nexport { t as getDevToolsHook, n as setDevToolsHook };\n\n//# sourceMappingURL=devtools-hook.js.map","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, r as RippleEnvironmentError, e as RippleError, i as RippleInfiniteLoopError, a as RippleInvalidCleanupError, o as RippleInvalidStoreError };\n\n//# sourceMappingURL=errors.js.map","//#region src/tracking.ts\nvar e = 0, t = () => ++e, n = () => e, r = () => ({\n\tactiveDirty: \"a\",\n\tbatchDepth: 0,\n\tdirtyWithEffectSubsA: /* @__PURE__ */ new Set(),\n\tdirtyWithEffectSubsB: /* @__PURE__ */ new Set(),\n\tpendingSubscribers: /* @__PURE__ */ new Set()\n}), i = {\n\tscheduling: r(),\n\tscopeCleanups: null,\n\ttracking: null\n}, a = null, o = () => a === null ? i : a.get(), s = () => o().scheduling, c = () => a !== null, l = () => o().tracking, u = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\ttracking: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\ttracking: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, d = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\tscopeCleanups: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\tscopeCleanups: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, f = () => o().scopeCleanups, p = (e) => {\n\tlet t = l();\n\tt?.kind === \"effect\" ? t.cleanups.push(e) : f()?.push(e);\n}, m = (e) => {\n\tlet t = a;\n\treturn a = e, t;\n}, h = (e, t) => {\n\tlet n = l();\n\treturn n === null ? t() : u({\n\t\t...n,\n\t\tsourceObserver: e\n\t}, t);\n}, g = (e) => u(null, e), _ = (e) => {\n\tlet t = l();\n\tif (t !== null) {\n\t\tif (t.sourceObserver?.(e), t.kind === \"computed\") t.depCollector.push({\n\t\t\tsource: e,\n\t\t\tversion: e.version\n\t\t});\n\t\telse if (t.kind === \"effect\") {\n\t\t\tlet n = t.effect;\n\t\t\te.addEffectSub(n), t.subscriptions.add(() => e.removeEffectSub(n)), t.deps.set(e, e.version);\n\t\t}\n\t}\n};\n//#endregion\nexport { m as _installContextHook, p as autoRegisterDisposal, r as createSchedulingState, n as getRevision, s as getSchedulingState, f as getScopeCleanups, l as getTracking, c as hasContextHook, t as tickRevision, _ as trackSource, g as untrack, d as withScopeCleanups, h as withSourceObserver, u as withTracking };\n\n//# sourceMappingURL=tracking.js.map","//#region src/_error-utils.ts\nvar e = (e) => e instanceof Error ? e : /* @__PURE__ */ Error(`Non-Error thrown: ${String(e)}`), t = (t) => {\n\tlet n = [];\n\tfor (let r of t) try {\n\t\tr();\n\t} catch (t) {\n\t\tn.push(e(t));\n\t}\n\treturn n;\n}, n = (e, n) => {\n\tlet r = t(e);\n\tif (r.length === 1) throw r[0];\n\tif (r.length > 0) throw AggregateError(r, n);\n}, r = (t, n, r) => {\n\tthrow n.length === 0 ? t : AggregateError([e(t), ...n], r, { cause: e(t) });\n};\n//#endregion\nexport { t as collectErrors, e as ensureError, r as rethrowWith, n as runAll };\n\n//# sourceMappingURL=_error-utils.js.map","//#region src/_dev.ts\nvar e = !globalThis.__RIPPLE_PROD__;\nfunction t(t) {\n\te && console.warn(`[@vielzeug/ripple] ${t}`);\n}\n//#endregion\nexport { t as warn };\n\n//# sourceMappingURL=_dev.js.map","import { runAll as e } from \"./_error-utils.js\";\nimport { RippleInfiniteLoopError as t } from \"./errors.js\";\nimport { warn as n } from \"./_dev.js\";\nimport { getSchedulingState as r, hasContextHook as i } from \"./tracking.js\";\nvar a = !1, o = 0, s = [], c = (e) => e.activeDirty === \"a\" ? e.dirtyWithEffectSubsA : e.dirtyWithEffectSubsB, l = (e, t) => {\n\tlet n = ++o;\n\tfor (let n of t.effectSubs()) e.pendingSubscribers.add(n);\n\tfor (let e of t.computedSubs()) s.push(e);\n\ttry {\n\t\tfor (; s.length > 0;) {\n\t\t\tlet t = s.pop();\n\t\t\tif (t.lastPropEpoch_ !== n && (t.lastPropEpoch_ = n, t.markDirty())) {\n\t\t\t\tt.effectSubs().size > 0 && c(e).add(t);\n\t\t\t\tfor (let e of t.computedSubs()) s.push(e);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ts.length = 0;\n\t}\n}, u = (e) => {\n\tfor (; c(e).size > 0;) {\n\t\tlet t = c(e);\n\t\te.activeDirty = e.activeDirty === \"a\" ? \"b\" : \"a\", c(e).clear();\n\t\tfor (let n of t) if (n.hasSubscribers() && n.refreshIfDirty()) {\n\t\t\tfor (let t of n.effectSubs()) e.pendingSubscribers.add(t);\n\t\t\tfor (let t of n.computedSubs()) t.markDirty() && t.effectSubs().size > 0 && c(e).add(t);\n\t\t}\n\t\tt.clear();\n\t}\n}, d = (n) => {\n\tlet r = 0;\n\tfor (; n.pendingSubscribers.size > 0 || c(n).size > 0;) {\n\t\tif (++r > 100) throw new t(\"infinite flush loop (> 100 iterations)\");\n\t\tif (c(n).size > 0 && u(n), n.pendingSubscribers.size === 0) continue;\n\t\tlet i = [...n.pendingSubscribers];\n\t\tn.pendingSubscribers.clear(), e(i, \"subscriber errors\");\n\t}\n}, f = globalThis.process?.versions != null, p = (e) => {\n\tif (!e.hasSubscribers()) return;\n\t!a && f && !i() && (a = !0, n(\"Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.\"));\n\tlet t = r();\n\tl(t, e), t.batchDepth === 0 && d(t);\n}, m = (e) => {\n\tlet t = r();\n\tt.batchDepth++;\n\tlet n;\n\ttry {\n\t\tn = e();\n\t} catch (e) {\n\t\tthrow t.batchDepth--, t.batchDepth === 0 && (t.pendingSubscribers.clear(), t.dirtyWithEffectSubsA.clear(), t.dirtyWithEffectSubsB.clear()), e;\n\t}\n\treturn t.batchDepth--, t.batchDepth === 0 && d(t), n;\n};\n//#endregion\nexport { m as batch, p as notifyNodeChange };\n\n//# sourceMappingURL=scheduling.js.map","//#region src/subscription.ts\nvar e = class {\n\tfn_;\n\tdisposed_ = !1;\n\tconstructor(e) {\n\t\tthis.fn_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (this.disposed_) return;\n\t\tthis.disposed_ = !0;\n\t\tlet e = this.fn_;\n\t\tthis.fn_ = null, e();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, t = class {\n\tawaitDone_;\n\tgetCurrentRun_;\n\tsyncStop_;\n\tasyncDisposePromise_ = null;\n\tconstructor(e, t, n) {\n\t\tthis.awaitDone_ = t, this.getCurrentRun_ = n, this.syncStop_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.syncStop_.disposed;\n\t}\n\tdispose() {\n\t\tthis.syncStop_.dispose();\n\t}\n\trun() {\n\t\treturn this.getCurrentRun_() ?? Promise.resolve();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\t[Symbol.asyncDispose]() {\n\t\treturn this.asyncDisposePromise_ === null ? (this.dispose(), this.asyncDisposePromise_ = this.awaitDone_(), this.asyncDisposePromise_) : this.asyncDisposePromise_;\n\t}\n};\n//#endregion\nexport { t as AsyncSubscriptionImpl, e as SubscriptionImpl };\n\n//# sourceMappingURL=subscription.js.map","//#region src/symbols.ts\nvar e = Symbol(\"ripple.is-signal\"), t = Symbol(\"ripple.is-computed\"), n = Symbol(\"ripple.is-store\"), r = Symbol(\"ripple.uninitialized\");\n//#endregion\nexport { t as IS_COMPUTED, e as IS_SIGNAL, n as IS_STORE, r as UNINITIALIZED };\n\n//# sourceMappingURL=symbols.js.map","import { IS_COMPUTED as e, IS_SIGNAL as t } from \"./symbols.js\";\n//#region src/reactive-base.ts\nvar n = new FinalizationRegistry(({ key: e, map: t }) => {\n\tt.delete(e);\n}), r = class {\n\tversion = 0;\n\tname;\n\t[t] = !0;\n\tcomputedSubs_ = /* @__PURE__ */ new Map();\n\teffectSubs_ = /* @__PURE__ */ new Set();\n\tconstructor(e) {\n\t\tthis.name = e;\n\t}\n\taddComputedSub(e) {\n\t\tlet t = new WeakRef(e);\n\t\tthis.computedSubs_.set(e, t), n.register(e, {\n\t\t\tkey: e,\n\t\t\tmap: this.computedSubs_\n\t\t}, t);\n\t}\n\tremoveComputedSub(e) {\n\t\tlet t = this.computedSubs_.get(e);\n\t\tt !== void 0 && (this.computedSubs_.delete(e), n.unregister(t));\n\t}\n\taddEffectSub(e) {\n\t\tthis.effectSubs_.add(e);\n\t}\n\tremoveEffectSub(e) {\n\t\tthis.effectSubs_.delete(e);\n\t}\n\tclearSubscribers() {\n\t\tfor (let e of this.computedSubs_.values()) n.unregister(e);\n\t\tthis.computedSubs_.clear(), this.effectSubs_.clear();\n\t}\n\thasSubscribers() {\n\t\tif (this.effectSubs_.size > 0) return !0;\n\t\tfor (let e of this.computedSubs_.values()) if (e.deref() !== void 0) return !0;\n\t\treturn !1;\n\t}\n\t*computedSubs() {\n\t\tfor (let [e, t] of this.computedSubs_) {\n\t\t\tlet r = t.deref();\n\t\t\tr === void 0 ? (this.computedSubs_.delete(e), n.unregister(t)) : yield r;\n\t\t}\n\t}\n\teffectSubs() {\n\t\treturn this.effectSubs_;\n\t}\n}, i = class extends r {\n\t[e] = !0;\n\tlastPropEpoch_ = 0;\n};\n//#endregion\nexport { i as ComputedBase, r as ReactiveBase };\n\n//# sourceMappingURL=reactive-base.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { ensureError as t } from \"./_error-utils.js\";\nimport { RippleComputedCycleError as n } from \"./errors.js\";\nimport { autoRegisterDisposal as r, getRevision as i, trackSource as a, withTracking as o } from \"./tracking.js\";\nimport { SubscriptionImpl as s } from \"./subscription.js\";\nimport { UNINITIALIZED as c } from \"./symbols.js\";\nimport { ComputedBase as l } from \"./reactive-base.js\";\n//#region src/computed.ts\nvar u = class extends l {\n\tvalue_;\n\tdirty_;\n\tcomputing_;\n\tdisposed_;\n\tdeps_;\n\tcompute_;\n\tequals_;\n\tmaxRevision_;\n\tconstructor(e, t) {\n\t\tlet { equals: n, name: r } = t ?? {};\n\t\tsuper(r), this.value_ = c, this.dirty_ = !0, this.computing_ = !1, this.disposed_ = !1, this.deps_ = [], this.maxRevision_ = -1, this.compute_ = e, this.equals_ = n === void 0 ? Object.is : (e, t) => n(e, t);\n\t}\n\tmarkDirty() {\n\t\treturn this.disposed_ || this.dirty_ ? !1 : (this.dirty_ = !0, !0);\n\t}\n\trefreshIfDirty() {\n\t\tif (!this.dirty_) return !1;\n\t\tif (i() <= this.maxRevision_) return this.dirty_ = !1, !1;\n\t\tif (this.deps_.length > 0) {\n\t\t\tlet e = !0;\n\t\t\tfor (let t of this.deps_) {\n\t\t\t\tlet n = t.source;\n\t\t\t\tif (\"refreshIfDirty\" in n && n.refreshIfDirty(), n.version !== t.version) {\n\t\t\t\t\te = !1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (e) return this.dirty_ = !1, this.maxRevision_ = i(), !1;\n\t\t}\n\t\treturn this.recompute();\n\t}\n\trunCompute(e) {\n\t\ttry {\n\t\t\treturn o({\n\t\t\t\tcomputed: this,\n\t\t\t\tdepCollector: e,\n\t\t\t\tkind: \"computed\"\n\t\t\t}, this.compute_);\n\t\t} catch (e) {\n\t\t\tthrow t(e);\n\t\t}\n\t}\n\trecompute() {\n\t\tif (this.computing_) throw new n(`computed cycle detected${this.name ? ` \"${this.name}\"` : \"\"}`);\n\t\tthis.computing_ = !0;\n\t\ttry {\n\t\t\tlet t = [];\n\t\t\te()?.compute?.({ name: this.name });\n\t\t\tlet n = this.runCompute(t);\n\t\t\treturn this.dirty_ = !1, this.maxRevision_ = i(), this.updateDeps(t), this.value_ === c || !this.equals_(this.value_, n) ? (this.value_ = n, this.version++, !0) : !1;\n\t\t} finally {\n\t\t\tthis.computing_ = !1;\n\t\t}\n\t}\n\tupdateDeps(e) {\n\t\tlet t = this.deps_;\n\t\tif (t.length === e.length && t.every((t, n) => t.source === e[n].source)) {\n\t\t\tfor (let n = 0; n < e.length; n++) t[n].version = e[n].version;\n\t\t\treturn;\n\t\t}\n\t\tlet n = new Set(t.map((e) => e.source)), r = new Set(e.map((e) => e.source));\n\t\tfor (let e of t) r.has(e.source) || e.source.removeComputedSub(this);\n\t\tfor (let t of e) n.has(t.source) || t.source.addComputedSub(this);\n\t\tthis.deps_ = e;\n\t}\n\tget value() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), a(this), this.value_);\n\t}\n\tpeek() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), this.value_);\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new s(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.refreshIfDirty(), this.addEffectSub(e), new s(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (!this.disposed_) {\n\t\t\tthis.disposed_ = !0;\n\t\t\tfor (let e of this.deps_) e.source.removeComputedSub(this);\n\t\t\tthis.deps_ = [], this.clearSubscribers(), e()?.dispose?.({\n\t\t\t\tkind: \"computed\",\n\t\t\t\tname: this.name\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, d = (e, t) => {\n\tlet n = new u(e, t);\n\treturn r(() => n.dispose()), n;\n};\n//#endregion\nexport { u as ComputedImpl, d as computed };\n\n//# sourceMappingURL=computed.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { tickRevision as t, trackSource as n } from \"./tracking.js\";\nimport { notifyNodeChange as r } from \"./scheduling.js\";\nimport { SubscriptionImpl as i } from \"./subscription.js\";\nimport { ReactiveBase as a } from \"./reactive-base.js\";\n//#region src/signal.ts\nvar o = class extends a {\n\tvalue_;\n\tequals_;\n\tdisposed_;\n\tconstructor(e, t, n) {\n\t\tsuper(n), this.value_ = e, this.equals_ = t ?? Object.is, this.disposed_ = !1;\n\t}\n\tget value() {\n\t\treturn this.disposed_ || n(this), this.value_;\n\t}\n\tset value(n) {\n\t\tif (this.disposed_ || this.equals_(this.value_, n)) return;\n\t\tlet i = this.value_;\n\t\tthis.value_ = n, this.version = t(), e()?.write?.({\n\t\t\tname: this.name,\n\t\t\tnewValue: n,\n\t\t\toldValue: i\n\t\t}), r(this);\n\t}\n\tpeek() {\n\t\treturn this.value_;\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new i(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.addEffectSub(e), new i(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tthis.disposed_ || (this.disposed_ = !0, this.clearSubscribers(), e()?.dispose?.({\n\t\t\tkind: \"signal\",\n\t\t\tname: this.name\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, s = (e, t) => new o(e, t?.equals, t?.name);\n//#endregion\nexport { o as SignalImpl, s as signal };\n\n//# sourceMappingURL=signal.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n const disposables = [\n undoStack,\n redoStack,\n pending,\n processing,\n canUndo,\n canRedo,\n historySize,\n isProcessing,\n pendingCount,\n historySnapshot,\n ];\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n\n for (const d of disposables) d.dispose();\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"mEAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE,UAAY,IAwB9C,EACN,KAAO,IAAW,CAChB,IAAI,EACA,EAAW,GAEf,IAAK,IAAM,IAAK,CAAC,GAAG,CAAQ,CAAC,CAAC,QAAQ,EACpC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,OAAS,EAAK,CACZ,AAEE,KADA,EAAa,EACF,GAEf,CAGF,GAAI,EAAU,MAAM,CACtB,EACA,IAAA,EACN,CACF,CC3DA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,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src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.js","../../ripple/dist/_store.js","../../ripple/dist/_watch.js","../../ripple/dist/index.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, e as RippleError, r as RippleInfiniteLoopError };\n\n//# sourceMappingURL=errors.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleInfiniteLoopError as n } from \"./errors.js\";\n//#region src/runtime.ts\nvar r = Symbol(\"ripple.reactive\"), i = Symbol(\"ripple.signal\"), a = Symbol(\"ripple.computed\"), o = 100, s = Symbol(\"ripple.unset\"), c = class {\n\t[r] = !0;\n\tdependents = /* @__PURE__ */ new Set();\n\tname;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tsubscribe(e) {\n\t\tthis.peek();\n\t\tlet t = {\n\t\t\tdependencies: /* @__PURE__ */ new Set(),\n\t\t\tonDependencyChanged: () => this.runtime.enqueueListener(e)\n\t\t};\n\t\treturn this.dependents.add(t), () => this.dependents.delete(t);\n\t}\n\tnotify() {\n\t\tfor (let e of [...this.dependents]) e.onDependencyChanged();\n\t}\n}, l = class extends c {\n\t[i] = !0;\n\tcurrent;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.runtime.track(this), this.current;\n\t}\n\tset value(e) {\n\t\tif (this.equals(this.current, e)) return;\n\t\tlet t = this.current;\n\t\tthis.current = e, this.runtime.emit({\n\t\t\tkind: \"write\",\n\t\t\tname: this.name,\n\t\t\tnext: e,\n\t\t\tprevious: t\n\t\t}), this.runtime.propagate(() => this.notify());\n\t}\n\tpeek() {\n\t\treturn this.current;\n\t}\n}, u = class extends c {\n\t[a] = !0;\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = s;\n\tderive;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.refresh(), this.runtime.track(this), this.current;\n\t}\n\tpeek() {\n\t\treturn this.refresh(), this.current;\n\t}\n\tonDependencyChanged() {\n\t\tthis.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());\n\t}\n\tdispose() {\n\t\tthis.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());\n\t}\n\trefresh() {\n\t\tif (!this.dirty || this.disposed) return !1;\n\t\tif (this.computing) {\n\t\t\tlet t = this.name === void 0 ? \"\" : ` \"${this.name}\"`;\n\t\t\tthrow new e(`computed cycle detected${t}`);\n\t\t}\n\t\tthis.computing = !0, this.runtime.emit({\n\t\t\tkind: \"compute\",\n\t\t\tname: this.name\n\t\t});\n\t\ttry {\n\t\t\tlet e = this.runtime.collect(this, this.derive), t = this.current === s || !this.equals(this.current, e);\n\t\t\treturn this.current = e, this.dirty = !1, t;\n\t\t} finally {\n\t\t\tthis.computing = !1;\n\t\t}\n\t}\n}, d = class {\n\tdisposalController = new AbortController();\n\towned = /* @__PURE__ */ new Set();\n\tname;\n\tisDisposed = !1;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\trun(e) {\n\t\tif (this.isDisposed) throw new t(\"Cannot run a disposed scope.\");\n\t\treturn this.runtime.withScope(this, e);\n\t}\n\tdispose() {\n\t\tif (!this.isDisposed) {\n\t\t\tthis.isDisposed = !0;\n\t\t\tfor (let e of [...this.owned].reverse()) e.dispose();\n\t\t\tthis.owned.clear(), this.disposalController.abort(), this.runtime.emit({\n\t\t\t\tkind: \"dispose\",\n\t\t\t\tname: this.name,\n\t\t\t\tnode: \"scope\"\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, f = class {\n\tdependencies = /* @__PURE__ */ new Set();\n\tdisposalController = new AbortController();\n\tcleanup;\n\tisDisposed = !1;\n\towner;\n\tscheduled = !1;\n\tcallback;\n\toptions;\n\truntime;\n\tconstructor(e, t, n) {\n\t\tthis.runtime = e, this.callback = t, this.options = n;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\tonDependencyChanged() {\n\t\tif (!this.isDisposed) {\n\t\t\tif (this.options?.scheduler === \"microtask\") {\n\t\t\t\tif (this.scheduled) return;\n\t\t\t\tthis.scheduled = !0, queueMicrotask(() => {\n\t\t\t\t\tthis.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.runtime.enqueue(this);\n\t\t}\n\t}\n\trun() {\n\t\tif (this.isDisposed) return;\n\t\tthis.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({\n\t\t\tkind: \"effect\",\n\t\t\tname: this.options?.name\n\t\t});\n\t\tlet e = new d(this.runtime);\n\t\ttry {\n\t\t\tlet t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));\n\t\t\tthis.owner = e, this.cleanup = typeof t == \"function\" ? t : void 0;\n\t\t} catch (t) {\n\t\t\te.dispose(), this.runtime.report(t, {\n\t\t\t\tkind: \"effect\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({\n\t\t\tkind: \"dispose\",\n\t\t\tname: this.options?.name,\n\t\t\tnode: \"effect\"\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\trunCleanup() {\n\t\tlet e = this.cleanup;\n\t\tif (this.cleanup = void 0, e !== void 0) try {\n\t\t\te();\n\t\t} catch (e) {\n\t\t\tthis.runtime.report(e, {\n\t\t\t\tkind: \"cleanup\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n}, p = class {\n\tactiveEffectScope;\n\tactiveObserver;\n\tactiveScope;\n\tflushDepth = 0;\n\tflushing = !1;\n\tpending = /* @__PURE__ */ new Set();\n\tlisteners = /* @__PURE__ */ new Set();\n\trootScope;\n\tobserver;\n\tonError;\n\tconstructor(e) {\n\t\tthis.observer = e?.observer, this.onError = e?.onError ?? ((e) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}), this.rootScope = new d(this, \"runtime\"), this.activeScope = this.rootScope;\n\t}\n\tsignal = (e, t) => new l(this, e, t);\n\tcomputed = (e, t) => {\n\t\tlet n = new u(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n;\n\t};\n\teffect = (e, t) => {\n\t\tlet n = new f(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;\n\t};\n\tcreateScope = (e) => {\n\t\tlet t = new d(this, e);\n\t\treturn this.activeScope.owned.add(t), t;\n\t};\n\tbatch = (e) => this.propagate(e);\n\tuntrack = (e) => this.withObserver(void 0, e);\n\tdispose() {\n\t\tthis.rootScope.dispose();\n\t}\n\ttrack(e) {\n\t\tlet t = this.activeObserver;\n\t\tt?.collecting !== void 0 && t.collecting.add(e);\n\t}\n\tclearDependencies(e) {\n\t\tfor (let t of e.dependencies) t.dependents.delete(e);\n\t\te.dependencies.clear();\n\t}\n\tcollect(e, t) {\n\t\treturn this.collectWith(e, t, !1);\n\t}\n\tcollectEffect(e, t) {\n\t\treturn this.collectWith(e, t, !0);\n\t}\n\twithEffectScope(e, t) {\n\t\tlet n = this.activeEffectScope;\n\t\tthis.activeEffectScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n;\n\t\t}\n\t}\n\twithObserver(e, t) {\n\t\tlet n = this.activeObserver;\n\t\tthis.activeObserver = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeObserver = n;\n\t\t}\n\t}\n\twithScope(e, t) {\n\t\tlet n = this.activeEffectScope, r = this.activeScope;\n\t\tthis.activeEffectScope = void 0, this.activeScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n, this.activeScope = r;\n\t\t}\n\t}\n\tenqueue(e) {\n\t\tthis.pending.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tenqueueListener(e) {\n\t\tthis.listeners.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tpropagate(e) {\n\t\tthis.flushDepth++;\n\t\ttry {\n\t\t\treturn e();\n\t\t} finally {\n\t\t\tthis.flushDepth--, this.flushDepth === 0 && this.flush();\n\t\t}\n\t}\n\temit(e) {\n\t\ttry {\n\t\t\tthis.observer?.(e);\n\t\t} catch (t) {\n\t\t\tthis.report(t, {\n\t\t\t\tkind: \"observer\",\n\t\t\t\tname: e.name\n\t\t\t});\n\t\t}\n\t}\n\treport(e, t) {\n\t\ttry {\n\t\t\tthis.onError(e, t);\n\t\t} catch (e) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}\n\t}\n\tcollectWith(e, t, n) {\n\t\tlet r = this.activeObserver, i = /* @__PURE__ */ new Set();\n\t\te.collecting = i, this.activeObserver = e;\n\t\ttry {\n\t\t\tlet n = t();\n\t\t\treturn this.commitDependencies(e, i), n;\n\t\t} catch (t) {\n\t\t\tthrow n && this.commitDependencies(e, i), t;\n\t\t} finally {\n\t\t\te.collecting = void 0, this.activeObserver = r;\n\t\t}\n\t}\n\tcommitDependencies(e, t) {\n\t\tfor (let n of e.dependencies) t.has(n) || n.dependents.delete(e);\n\t\tfor (let n of t) e.dependencies.has(n) || n.dependents.add(e);\n\t\te.dependencies.clear();\n\t\tfor (let n of t) e.dependencies.add(n);\n\t}\n\tflush() {\n\t\tif (this.flushing) return;\n\t\tthis.flushing = !0;\n\t\tlet e = 0;\n\t\ttry {\n\t\t\tfor (; this.pending.size > 0 || this.listeners.size > 0;) {\n\t\t\t\tif (++e > o) throw new n(`infinite reactive flush (>${o} iterations)`);\n\t\t\t\tlet t = [...this.pending], r = [...this.listeners];\n\t\t\t\tthis.pending.clear(), this.listeners.clear();\n\t\t\t\tfor (let e of t) e.run();\n\t\t\t\tfor (let e of r) try {\n\t\t\t\t\te();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.report(e, { kind: \"listener\" });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.flushing = !1;\n\t\t}\n\t}\n}, m = (e) => typeof e == \"object\" && !!e && r in e;\n//#endregion\nexport { p as ReactiveRuntime, m as isReactive };\n\n//# sourceMappingURL=runtime.js.map","//#region src/_async.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = e.signal({ status: \"pending\" }, { name: r?.name }), a = e.signal(0), o = new AbortController(), s, c = !1, l = () => {\n\t\ta.value, s?.abort();\n\t\tlet e = i.peek(), r = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, o;\n\t\ttry {\n\t\t\to = t();\n\t\t} catch (e) {\n\t\t\ti.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tlet l = new AbortController();\n\t\ts = l, i.value = r === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: r,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(n(o, { signal: l.signal }));\n\t\t} catch (e) {\n\t\t\tu = Promise.reject(e);\n\t\t}\n\t\tu.then((e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = {\n\t\t\t\tstatus: \"success\",\n\t\t\t\tvalue: e\n\t\t\t});\n\t\t}, (e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = e.effect(() => (l(), () => s?.abort()), { name: r?.name });\n\treturn u.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0, o.abort();\n\t}, { once: !0 }), {\n\t\tget disposalSignal() {\n\t\t\treturn o.signal;\n\t\t},\n\t\tdispose: () => u.dispose(),\n\t\tget disposed() {\n\t\t\treturn c;\n\t\t},\n\t\tget name() {\n\t\t\treturn i.name;\n\t\t},\n\t\tpeek: () => i.peek(),\n\t\treload: () => {\n\t\t\tc || (a.value = a.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => i.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn i.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createResource };\n\n//# sourceMappingURL=_async.js.map","//#region src/_store.ts\nvar e = (e) => (t, n) => {\n\tlet r = e.signal(t, { name: n?.name });\n\treturn {\n\t\tget name() {\n\t\t\treturn r.name;\n\t\t},\n\t\tpeek: () => r.peek(),\n\t\tset: (e) => {\n\t\t\tr.value = e;\n\t\t},\n\t\tsubscribe: (e) => r.subscribe(e),\n\t\tupdate: (e) => {\n\t\t\tr.value = e(r.peek());\n\t\t},\n\t\tget value() {\n\t\t\treturn r.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createStore };\n\n//# sourceMappingURL=_store.js.map","//#region src/_watch.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = typeof t == \"function\" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s, c = !1, l = e.effect(() => {\n\t\tlet e = i();\n\t\tif (o) {\n\t\t\to = !1, s = e, r?.immediate && n(e, void 0), c = r?.once === !0 && r.immediate === !0;\n\t\t\treturn;\n\t\t}\n\t\tif (a(s, e)) return;\n\t\tlet t = s;\n\t\ts = e, n(e, t), r?.once && l.dispose();\n\t}, { name: r?.name });\n\treturn c && l.dispose(), l;\n};\n//#endregion\nexport { e as createWatch };\n\n//# sourceMappingURL=_watch.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleError as n, RippleInfiniteLoopError as r } from \"./errors.js\";\nimport { ReactiveRuntime as i, isReactive as a } from \"./runtime.js\";\nimport { createResource as o } from \"./_async.js\";\nimport { createStore as s } from \"./_store.js\";\nimport { createWatch as c } from \"./_watch.js\";\n//#region src/index.ts\nvar l = (e) => {\n\tlet t = new i(e), n = o(t), r = s(t);\n\treturn {\n\t\tbatch: t.batch,\n\t\tcomputed: t.computed,\n\t\tcreateScope: t.createScope,\n\t\tcreateStore: r,\n\t\tdispose: () => t.dispose(),\n\t\teffect: t.effect,\n\t\tresource: n,\n\t\tsignal: t.signal,\n\t\tuntrack: t.untrack,\n\t\twatch: c(t)\n\t};\n}, u = l(), d = u.signal, f = u.computed, p = u.effect, m = u.batch, h = u.createScope, g = u.createStore, _ = u.resource, v = u.untrack, y = u.watch;\n//#endregion\nexport { e as RippleComputedCycleError, t as RippleDisposedScopeError, n as RippleError, r as RippleInfiniteLoopError, m as batch, f as computed, l as createRipple, h as createScope, g as createStore, p as effect, a as isReactive, _ as resource, d as signal, v as untrack, y as watch };\n\n//# sourceMappingURL=index.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"mEAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IA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AC,CAC/D,CAEI,IAEJ,EAAU,MAAQ,EAAM,MAAM,EAAG,EAAE,EACnC,EAAU,MAAQ,CAAC,GAAG,EAAU,MAAO,CAAK,EAC9C,CAAC,CACH,CAEA,SAAS,GAAuB,CAC9B,OAAO,EAAQ,QAAS,SAAY,CAC9B,IAEJ,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EACrB,CAAC,CACH,CAEA,SAAS,GAAgB,CACvB,EAAa,GACb,EAAG,MAAM,EAET,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,CACrB,CAEA,MAAO,CACL,UACA,UAEA,QAEA,IAAI,gBAA8B,CAChC,OAAO,EAAG,MACZ,EACA,UACA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAyB,EAAgD,CAC1E,OAAO,EAAQ,SAAY,EAAM,EAAwB,CAAO,EAAG,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC1G,EAEA,cACA,kBACA,eACA,eAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,EAEA,CAAC,OAAO,UAAiB,CACvB,EAAQ,CACV,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,CACF,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../src/ledger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAwB,MAAM,EAAqB,aAAa,EAAE,MAAM,SAAS,CAAC;AAyB9F;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAE,aAAa,CAAC,KAAK,CAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CA0L/F"}
1
+ {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../src/ledger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAwB,MAAM,EAAqB,aAAa,EAAE,MAAM,SAAS,CAAC;AAyB9F;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAE,aAAa,CAAC,KAAK,CAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CA2K/F"}
@@ -1,2 +1,2 @@
1
- var Ledger=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var n=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},r=class extends n{},i=class extends n{},a=class extends n{},o=null,s=()=>o,c=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},l=class extends c{},u=class extends c{},d=0,f=()=>++d,p=()=>d,m={scheduling:{activeDirty:`a`,batchDepth:0,dirtyWithEffectSubsA:new Set,dirtyWithEffectSubsB:new Set,pendingSubscribers:new Set},scopeCleanups:null,tracking:null},h=null,g=()=>h===null?m:h.get(),_=()=>g().scheduling,v=()=>h!==null,y=()=>g().tracking,b=(e,t)=>{if(h!==null){let n=h.get();return h.run({...n,tracking:e},t)}let n=m;m={...m,tracking:e};try{return t()}finally{m=n}},x=()=>g().scopeCleanups,S=e=>{let t=y();t?.kind===`effect`?t.cleanups.push(e):x()?.push(e)},C=e=>{let t=y();if(t!==null){if(t.sourceObserver?.(e),t.kind===`computed`)t.depCollector.push({source:e,version:e.version});else if(t.kind===`effect`){let n=t.effect;e.addEffectSub(n),t.subscriptions.add(()=>e.removeEffectSub(n)),t.deps.set(e,e.version)}}},w=e=>e instanceof Error?e:Error(`Non-Error thrown: ${String(e)}`),T=e=>{let t=[];for(let n of e)try{n()}catch(e){t.push(w(e))}return t},E=(e,t)=>{let n=T(e);if(n.length===1)throw n[0];if(n.length>0)throw AggregateError(n,t)},D=!globalThis.__RIPPLE_PROD__;function O(e){D&&console.warn(`[@vielzeug/ripple] ${e}`)}var k=!1,A=0,j=[],M=e=>e.activeDirty===`a`?e.dirtyWithEffectSubsA:e.dirtyWithEffectSubsB,N=(e,t)=>{let n=++A;for(let n of t.effectSubs())e.pendingSubscribers.add(n);for(let e of t.computedSubs())j.push(e);try{for(;j.length>0;){let t=j.pop();if(t.lastPropEpoch_!==n&&(t.lastPropEpoch_=n,t.markDirty())){t.effectSubs().size>0&&M(e).add(t);for(let e of t.computedSubs())j.push(e)}}}finally{j.length=0}},P=e=>{for(;M(e).size>0;){let t=M(e);e.activeDirty=e.activeDirty===`a`?`b`:`a`,M(e).clear();for(let n of t)if(n.hasSubscribers()&&n.refreshIfDirty()){for(let t of n.effectSubs())e.pendingSubscribers.add(t);for(let t of n.computedSubs())t.markDirty()&&t.effectSubs().size>0&&M(e).add(t)}t.clear()}},F=e=>{let t=0;for(;e.pendingSubscribers.size>0||M(e).size>0;){if(++t>100)throw new u(`infinite flush loop (> 100 iterations)`);if(M(e).size>0&&P(e),e.pendingSubscribers.size===0)continue;let n=[...e.pendingSubscribers];e.pendingSubscribers.clear(),E(n,`subscriber errors`)}},I=globalThis.process?.versions!=null,L=e=>{if(!e.hasSubscribers())return;!k&&I&&!v()&&(k=!0,O(`Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.`));let t=_();N(t,e),t.batchDepth===0&&F(t)},R=class{fn_;disposed_=!1;constructor(e){this.fn_=e}get disposed(){return this.disposed_}dispose(){if(this.disposed_)return;this.disposed_=!0;let e=this.fn_;this.fn_=null,e()}[Symbol.dispose](){this.dispose()}},z=Symbol(`ripple.is-signal`),B=Symbol(`ripple.is-computed`),V=Symbol(`ripple.uninitialized`),H=new FinalizationRegistry(({key:e,map:t})=>{t.delete(e)}),U=class{version=0;name;[z]=!0;computedSubs_=new Map;effectSubs_=new Set;constructor(e){this.name=e}addComputedSub(e){let t=new WeakRef(e);this.computedSubs_.set(e,t),H.register(e,{key:e,map:this.computedSubs_},t)}removeComputedSub(e){let t=this.computedSubs_.get(e);t!==void 0&&(this.computedSubs_.delete(e),H.unregister(t))}addEffectSub(e){this.effectSubs_.add(e)}removeEffectSub(e){this.effectSubs_.delete(e)}clearSubscribers(){for(let e of this.computedSubs_.values())H.unregister(e);this.computedSubs_.clear(),this.effectSubs_.clear()}hasSubscribers(){if(this.effectSubs_.size>0)return!0;for(let e of this.computedSubs_.values())if(e.deref()!==void 0)return!0;return!1}*computedSubs(){for(let[e,t]of this.computedSubs_){let n=t.deref();n===void 0?(this.computedSubs_.delete(e),H.unregister(t)):yield n}}effectSubs(){return this.effectSubs_}},W=class extends U{[B]=!0;lastPropEpoch_=0},G=class extends W{value_;dirty_;computing_;disposed_;deps_;compute_;equals_;maxRevision_;constructor(e,t){let{equals:n,name:r}=t??{};super(r),this.value_=V,this.dirty_=!0,this.computing_=!1,this.disposed_=!1,this.deps_=[],this.maxRevision_=-1,this.compute_=e,this.equals_=n===void 0?Object.is:(e,t)=>n(e,t)}markDirty(){return this.disposed_||this.dirty_?!1:(this.dirty_=!0,!0)}refreshIfDirty(){if(!this.dirty_)return!1;if(p()<=this.maxRevision_)return this.dirty_=!1,!1;if(this.deps_.length>0){let e=!0;for(let t of this.deps_){let n=t.source;if(`refreshIfDirty`in n&&n.refreshIfDirty(),n.version!==t.version){e=!1;break}}if(e)return this.dirty_=!1,this.maxRevision_=p(),!1}return this.recompute()}runCompute(e){try{return b({computed:this,depCollector:e,kind:`computed`},this.compute_)}catch(e){throw w(e)}}recompute(){if(this.computing_)throw new l(`computed cycle detected${this.name?` "${this.name}"`:``}`);this.computing_=!0;try{let e=[];s()?.compute?.({name:this.name});let t=this.runCompute(e);return this.dirty_=!1,this.maxRevision_=p(),this.updateDeps(e),this.value_===V||!this.equals_(this.value_,t)?(this.value_=t,this.version++,!0):!1}finally{this.computing_=!1}}updateDeps(e){let t=this.deps_;if(t.length===e.length&&t.every((t,n)=>t.source===e[n].source)){for(let n=0;n<e.length;n++)t[n].version=e[n].version;return}let n=new Set(t.map(e=>e.source)),r=new Set(e.map(e=>e.source));for(let e of t)r.has(e.source)||e.source.removeComputedSub(this);for(let t of e)n.has(t.source)||t.source.addComputedSub(this);this.deps_=e}get value(){return this.disposed_?this.value_===V?void 0:this.value_:(this.refreshIfDirty(),C(this),this.value_)}peek(){return this.disposed_?this.value_===V?void 0:this.value_:(this.refreshIfDirty(),this.value_)}subscribe=e=>{if(this.disposed_){let e=new R(()=>{});return e.dispose(),e}return this.refreshIfDirty(),this.addEffectSub(e),new R(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){if(!this.disposed_){this.disposed_=!0;for(let e of this.deps_)e.source.removeComputedSub(this);this.deps_=[],this.clearSubscribers(),s()?.dispose?.({kind:`computed`,name:this.name})}}[Symbol.dispose](){this.dispose()}},K=(e,t)=>{let n=new G(e,t);return S(()=>n.dispose()),n},q=class extends U{value_;equals_;disposed_;constructor(e,t,n){super(n),this.value_=e,this.equals_=t??Object.is,this.disposed_=!1}get value(){return this.disposed_||C(this),this.value_}set value(e){if(this.disposed_||this.equals_(this.value_,e))return;let t=this.value_;this.value_=e,this.version=f(),s()?.write?.({name:this.name,newValue:e,oldValue:t}),L(this)}peek(){return this.value_}subscribe=e=>{if(this.disposed_){let e=new R(()=>{});return e.dispose(),e}return this.addEffectSub(e),new R(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){this.disposed_||(this.disposed_=!0,this.clearSubscribers(),s()?.dispose?.({kind:`signal`,name:this.name}))}[Symbol.dispose](){this.dispose()}},J=(e,t)=>new q(e,t?.equals,t?.name),Y=!globalThis.__LEDGER_PROD__;function X(e){Y&&console.warn(`[@vielzeug/ledger] ${e}`)}function Z(e){return e instanceof Error?e.message:String(e)}function Q(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function $(e={}){let{maxHistory:t=100,onRollbackError:n}=e;t<1&&X(`maxHistory must be >= 1; history tracking is disabled for this ledger.`);let o=J([],{name:`ledger:undoStack`}),s=J([],{name:`ledger:redoStack`}),c=J(0,{name:`ledger:pending`}),l=J(!1,{name:`ledger:processing`}),u=K(()=>o.value.length>0,{name:`ledger:canUndo`}),d=K(()=>s.value.length>0,{name:`ledger:canRedo`}),f=K(()=>o.value.length,{name:`ledger:historySize`}),p=K(()=>l.value,{name:`ledger:isProcessing`}),m=K(()=>c.value,{name:`ledger:pendingCount`}),h=K(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=[o,s,c,l,u,d,f,p,m,h],_=!1,v=Promise.resolve(),y=new AbortController;function b(e){return e?AbortSignal.any([e,y.signal]):y.signal}function x(e,t){if(_)return Promise.reject(new r(`Cannot call ${e}() on a disposed ledger.`));c.value++;let n=v.then(t).finally(()=>{_||c.value--});return v=n.catch(()=>{}),n}async function S(e){l.value=!0;try{await e()}finally{_||(l.value=!1)}}async function C(e,n){await S(async()=>{try{await e.execute(n)}catch(e){throw new i(Z(e),{cause:e})}if(_)return;let r=[...o.value,e];r.length>t&&r.shift(),o.value=r,s.value=[]})}async function w(e){let t=o.value;if(t.length===0)return;let r=t[t.length-1];await S(async()=>{if(r.rollback)try{await r.rollback(e)}catch(e){X(`rollback() threw for "${r.meta.label??`(unlabelled)`}". Stack position unchanged.`),n?.(new a(Z(e),{cause:e}),r.meta);return}_||(o.value=t.slice(0,-1),s.value=[...s.value,r])})}async function T(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await S(async()=>{try{await n.execute(e)}catch(e){throw new i(Z(e),{cause:e})}_||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function E(){return x(`clear`,async()=>{_||(o.value=[],s.value=[])})}function D(){_=!0,y.abort(),o.value=[],s.value=[];for(let e of g)e.dispose()}return{canRedo:d,canUndo:u,clear:E,get disposalSignal(){return y.signal},dispose:D,get disposed(){return _},do(e,t){return x(`do`,()=>C(Q(e),b(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return x(`redo`,()=>T(b(e?.signal)))},[Symbol.dispose](){D()},undo(e){return x(`undo`,()=>w(b(e?.signal)))}}}return e.LedgerDisposedError=r,e.LedgerError=n,e.LedgerExecutionError=i,e.LedgerRollbackError=a,e.compose=t,e.createLedger=$,e})({});
1
+ var Ledger=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var n=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},r=class extends n{},i=class extends n{},a=class extends n{},o=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},s=class extends o{},c=class extends o{},l=class extends o{},u=Symbol(`ripple.reactive`),d=Symbol(`ripple.signal`),f=Symbol(`ripple.computed`),p=100,m=Symbol(`ripple.unset`),h=class{[u]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.peek();let t={dependencies:new Set,onDependencyChanged:()=>this.runtime.enqueueListener(e)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},g=class extends h{[d]=!0;current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({kind:`write`,name:this.name,next:e,previous:t}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}},_=class extends h{[f]=!0;dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=m;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.refresh(),this.runtime.track(this),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){this.disposed||(this.dirty||=!0,this.dependents.size>0&&this.refresh()&&this.notify())}dispose(){this.disposed||(this.disposed=!0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing)throw new s(`computed cycle detected${this.name===void 0?``:` "${this.name}"`}`);this.computing=!0,this.runtime.emit({kind:`compute`,name:this.name});try{let e=this.runtime.collect(this,this.derive),t=this.current===m||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},v=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}run(e){if(this.isDisposed)throw new c(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.name,node:`scope`})}}[Symbol.dispose](){this.dispose()}},y=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;owner;scheduled=!1;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}onDependencyChanged(){if(!this.isDisposed){if(this.options?.scheduler===`microtask`){if(this.scheduled)return;this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.isDisposed||this.runtime.enqueue(this)});return}this.runtime.enqueue(this)}}run(){if(this.isDisposed)return;this.owner?.dispose(),this.owner=void 0,this.runCleanup(),this.runtime.emit({kind:`effect`,name:this.options?.name});let e=new v(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.owner=e,this.cleanup=typeof t==`function`?t:void 0}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.owner?.dispose(),this.owner=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.options?.name,node:`effect`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},b=class{activeEffectScope;activeObserver;activeScope;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;observer;onError;constructor(e){this.observer=e?.observer,this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new v(this,`runtime`),this.activeScope=this.rootScope}signal=(e,t)=>new g(this,e,t);computed=(e,t)=>{let n=new _(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{let t=new v(this,e);return this.activeScope.owned.add(t),t};batch=e=>this.propagate(e);untrack=e=>this.withObserver(void 0,e);dispose(){this.rootScope.dispose()}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,!1)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){try{this.observer?.(e)}catch(t){this.report(t,{kind:`observer`,name:e.name})}}report(e,t){try{this.onError(e,t)}catch(e){queueMicrotask(()=>{throw e})}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>p)throw new l(`infinite reactive flush (>${p} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},x=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o=new AbortController,s,c=!1,l=()=>{a.value,s?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,o;try{o=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;s=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(o,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!c&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!c&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},u=e.effect(()=>(l(),()=>s?.abort()),{name:r?.name});return u.disposalSignal.addEventListener(`abort`,()=>{c=!0,o.abort()},{once:!0}),{get disposalSignal(){return o.signal},dispose:()=>u.dispose(),get disposed(){return c},get name(){return i.name},peek:()=>i.peek(),reload:()=>{c||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}}},S=e=>(t,n)=>{let r=e.signal(t,{name:n?.name});return{get name(){return r.name},peek:()=>r.peek(),set:e=>{r.value=e},subscribe:e=>r.subscribe(e),update:e=>{r.value=e(r.peek())},get value(){return r.value}}},C=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s,c=!1,l=e.effect(()=>{let e=i();if(o){o=!1,s=e,r?.immediate&&n(e,void 0),c=r?.once===!0&&r.immediate===!0;return}if(a(s,e))return;let t=s;s=e,n(e,t),r?.once&&l.dispose()},{name:r?.name});return c&&l.dispose(),l},w=(e=>{let t=new b(e),n=x(t),r=S(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,createStore:r,dispose:()=>t.dispose(),effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:C(t)}})(),T=w.signal,E=w.computed;w.effect,w.batch,w.createScope,w.createStore,w.resource,w.untrack,w.watch;function D(e){return e instanceof Error?e.message:String(e)}function O(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function k(e={}){let{maxHistory:t=100,onRollbackError:n}=e,o=T([],{name:`ledger:undoStack`}),s=T([],{name:`ledger:redoStack`}),c=T(0,{name:`ledger:pending`}),l=T(!1,{name:`ledger:processing`}),u=E(()=>o.value.length>0,{name:`ledger:canUndo`}),d=E(()=>s.value.length>0,{name:`ledger:canRedo`}),f=E(()=>o.value.length,{name:`ledger:historySize`}),p=E(()=>l.value,{name:`ledger:isProcessing`}),m=E(()=>c.value,{name:`ledger:pendingCount`}),h=E(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=!1,_=Promise.resolve(),v=new AbortController;function y(e){return e?AbortSignal.any([e,v.signal]):v.signal}function b(e,t){if(g)return Promise.reject(new r(`Cannot call ${e}() on a disposed ledger.`));c.value++;let n=_.then(t).finally(()=>{g||c.value--});return _=n.catch(()=>{}),n}async function x(e){l.value=!0;try{await e()}finally{g||(l.value=!1)}}async function S(e,n){await x(async()=>{try{await e.execute(n)}catch(e){throw new i(D(e),{cause:e})}if(g)return;let r=[...o.value,e];r.length>t&&r.shift(),o.value=r,s.value=[]})}async function C(e){let t=o.value;if(t.length===0)return;let r=t[t.length-1];await x(async()=>{if(r.rollback)try{await r.rollback(e)}catch(e){`${r.meta.label??`(unlabelled)`}`,n?.(new a(D(e),{cause:e}),r.meta);return}g||(o.value=t.slice(0,-1),s.value=[...s.value,r])})}async function w(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{try{await n.execute(e)}catch(e){throw new i(D(e),{cause:e})}g||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function k(){return b(`clear`,async()=>{g||(o.value=[],s.value=[])})}function A(){g=!0,v.abort(),o.value=[],s.value=[]}return{canRedo:d,canUndo:u,clear:k,get disposalSignal(){return v.signal},dispose:A,get disposed(){return g},do(e,t){return b(`do`,()=>S(O(e),y(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return b(`redo`,()=>w(y(e?.signal)))},[Symbol.dispose](){A()},undo(e){return b(`undo`,()=>C(y(e?.signal)))}}}return e.LedgerDisposedError=r,e.LedgerError=n,e.LedgerExecutionError=i,e.LedgerRollbackError=a,e.compose=t,e.createLedger=k,e})({});
2
2
  //# sourceMappingURL=ledger.iife.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.iife.js","names":["e","t","n","e","t","n","r","i","a","o","e","t","n","r","i","a","o","s","c","l","u","d","f","p","m","e","t","n","r","e","t","o","s","u","d","t","e","i","n","r","e","t","n","r","t","e","l","c","i","o","t","n","a","s","e","r","a","n","t","e","r","i"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/devtools-hook.js","../../ripple/dist/errors.js","../../ripple/dist/tracking.js","../../ripple/dist/_error-utils.js","../../ripple/dist/_dev.js","../../ripple/dist/scheduling.js","../../ripple/dist/subscription.js","../../ripple/dist/symbols.js","../../ripple/dist/reactive-base.js","../../ripple/dist/computed.js","../../ripple/dist/signal.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/devtools-hook.ts\nvar e = null, t = () => e, n = (t) => {\n\te = t;\n};\n//#endregion\nexport { t as getDevToolsHook, n as setDevToolsHook };\n\n//# sourceMappingURL=devtools-hook.js.map","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, r as RippleEnvironmentError, e as RippleError, i as RippleInfiniteLoopError, a as RippleInvalidCleanupError, o as RippleInvalidStoreError };\n\n//# sourceMappingURL=errors.js.map","//#region src/tracking.ts\nvar e = 0, t = () => ++e, n = () => e, r = () => ({\n\tactiveDirty: \"a\",\n\tbatchDepth: 0,\n\tdirtyWithEffectSubsA: /* @__PURE__ */ new Set(),\n\tdirtyWithEffectSubsB: /* @__PURE__ */ new Set(),\n\tpendingSubscribers: /* @__PURE__ */ new Set()\n}), i = {\n\tscheduling: r(),\n\tscopeCleanups: null,\n\ttracking: null\n}, a = null, o = () => a === null ? i : a.get(), s = () => o().scheduling, c = () => a !== null, l = () => o().tracking, u = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\ttracking: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\ttracking: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, d = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\tscopeCleanups: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\tscopeCleanups: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, f = () => o().scopeCleanups, p = (e) => {\n\tlet t = l();\n\tt?.kind === \"effect\" ? t.cleanups.push(e) : f()?.push(e);\n}, m = (e) => {\n\tlet t = a;\n\treturn a = e, t;\n}, h = (e, t) => {\n\tlet n = l();\n\treturn n === null ? t() : u({\n\t\t...n,\n\t\tsourceObserver: e\n\t}, t);\n}, g = (e) => u(null, e), _ = (e) => {\n\tlet t = l();\n\tif (t !== null) {\n\t\tif (t.sourceObserver?.(e), t.kind === \"computed\") t.depCollector.push({\n\t\t\tsource: e,\n\t\t\tversion: e.version\n\t\t});\n\t\telse if (t.kind === \"effect\") {\n\t\t\tlet n = t.effect;\n\t\t\te.addEffectSub(n), t.subscriptions.add(() => e.removeEffectSub(n)), t.deps.set(e, e.version);\n\t\t}\n\t}\n};\n//#endregion\nexport { m as _installContextHook, p as autoRegisterDisposal, r as createSchedulingState, n as getRevision, s as getSchedulingState, f as getScopeCleanups, l as getTracking, c as hasContextHook, t as tickRevision, _ as trackSource, g as untrack, d as withScopeCleanups, h as withSourceObserver, u as withTracking };\n\n//# sourceMappingURL=tracking.js.map","//#region src/_error-utils.ts\nvar e = (e) => e instanceof Error ? e : /* @__PURE__ */ Error(`Non-Error thrown: ${String(e)}`), t = (t) => {\n\tlet n = [];\n\tfor (let r of t) try {\n\t\tr();\n\t} catch (t) {\n\t\tn.push(e(t));\n\t}\n\treturn n;\n}, n = (e, n) => {\n\tlet r = t(e);\n\tif (r.length === 1) throw r[0];\n\tif (r.length > 0) throw AggregateError(r, n);\n}, r = (t, n, r) => {\n\tthrow n.length === 0 ? t : AggregateError([e(t), ...n], r, { cause: e(t) });\n};\n//#endregion\nexport { t as collectErrors, e as ensureError, r as rethrowWith, n as runAll };\n\n//# sourceMappingURL=_error-utils.js.map","//#region src/_dev.ts\nvar e = !globalThis.__RIPPLE_PROD__;\nfunction t(t) {\n\te && console.warn(`[@vielzeug/ripple] ${t}`);\n}\n//#endregion\nexport { t as warn };\n\n//# sourceMappingURL=_dev.js.map","import { runAll as e } from \"./_error-utils.js\";\nimport { RippleInfiniteLoopError as t } from \"./errors.js\";\nimport { warn as n } from \"./_dev.js\";\nimport { getSchedulingState as r, hasContextHook as i } from \"./tracking.js\";\nvar a = !1, o = 0, s = [], c = (e) => e.activeDirty === \"a\" ? e.dirtyWithEffectSubsA : e.dirtyWithEffectSubsB, l = (e, t) => {\n\tlet n = ++o;\n\tfor (let n of t.effectSubs()) e.pendingSubscribers.add(n);\n\tfor (let e of t.computedSubs()) s.push(e);\n\ttry {\n\t\tfor (; s.length > 0;) {\n\t\t\tlet t = s.pop();\n\t\t\tif (t.lastPropEpoch_ !== n && (t.lastPropEpoch_ = n, t.markDirty())) {\n\t\t\t\tt.effectSubs().size > 0 && c(e).add(t);\n\t\t\t\tfor (let e of t.computedSubs()) s.push(e);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ts.length = 0;\n\t}\n}, u = (e) => {\n\tfor (; c(e).size > 0;) {\n\t\tlet t = c(e);\n\t\te.activeDirty = e.activeDirty === \"a\" ? \"b\" : \"a\", c(e).clear();\n\t\tfor (let n of t) if (n.hasSubscribers() && n.refreshIfDirty()) {\n\t\t\tfor (let t of n.effectSubs()) e.pendingSubscribers.add(t);\n\t\t\tfor (let t of n.computedSubs()) t.markDirty() && t.effectSubs().size > 0 && c(e).add(t);\n\t\t}\n\t\tt.clear();\n\t}\n}, d = (n) => {\n\tlet r = 0;\n\tfor (; n.pendingSubscribers.size > 0 || c(n).size > 0;) {\n\t\tif (++r > 100) throw new t(\"infinite flush loop (> 100 iterations)\");\n\t\tif (c(n).size > 0 && u(n), n.pendingSubscribers.size === 0) continue;\n\t\tlet i = [...n.pendingSubscribers];\n\t\tn.pendingSubscribers.clear(), e(i, \"subscriber errors\");\n\t}\n}, f = globalThis.process?.versions != null, p = (e) => {\n\tif (!e.hasSubscribers()) return;\n\t!a && f && !i() && (a = !0, n(\"Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.\"));\n\tlet t = r();\n\tl(t, e), t.batchDepth === 0 && d(t);\n}, m = (e) => {\n\tlet t = r();\n\tt.batchDepth++;\n\tlet n;\n\ttry {\n\t\tn = e();\n\t} catch (e) {\n\t\tthrow t.batchDepth--, t.batchDepth === 0 && (t.pendingSubscribers.clear(), t.dirtyWithEffectSubsA.clear(), t.dirtyWithEffectSubsB.clear()), e;\n\t}\n\treturn t.batchDepth--, t.batchDepth === 0 && d(t), n;\n};\n//#endregion\nexport { m as batch, p as notifyNodeChange };\n\n//# sourceMappingURL=scheduling.js.map","//#region src/subscription.ts\nvar e = class {\n\tfn_;\n\tdisposed_ = !1;\n\tconstructor(e) {\n\t\tthis.fn_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (this.disposed_) return;\n\t\tthis.disposed_ = !0;\n\t\tlet e = this.fn_;\n\t\tthis.fn_ = null, e();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, t = class {\n\tawaitDone_;\n\tgetCurrentRun_;\n\tsyncStop_;\n\tasyncDisposePromise_ = null;\n\tconstructor(e, t, n) {\n\t\tthis.awaitDone_ = t, this.getCurrentRun_ = n, this.syncStop_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.syncStop_.disposed;\n\t}\n\tdispose() {\n\t\tthis.syncStop_.dispose();\n\t}\n\trun() {\n\t\treturn this.getCurrentRun_() ?? Promise.resolve();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\t[Symbol.asyncDispose]() {\n\t\treturn this.asyncDisposePromise_ === null ? (this.dispose(), this.asyncDisposePromise_ = this.awaitDone_(), this.asyncDisposePromise_) : this.asyncDisposePromise_;\n\t}\n};\n//#endregion\nexport { t as AsyncSubscriptionImpl, e as SubscriptionImpl };\n\n//# sourceMappingURL=subscription.js.map","//#region src/symbols.ts\nvar e = Symbol(\"ripple.is-signal\"), t = Symbol(\"ripple.is-computed\"), n = Symbol(\"ripple.is-store\"), r = Symbol(\"ripple.uninitialized\");\n//#endregion\nexport { t as IS_COMPUTED, e as IS_SIGNAL, n as IS_STORE, r as UNINITIALIZED };\n\n//# sourceMappingURL=symbols.js.map","import { IS_COMPUTED as e, IS_SIGNAL as t } from \"./symbols.js\";\n//#region src/reactive-base.ts\nvar n = new FinalizationRegistry(({ key: e, map: t }) => {\n\tt.delete(e);\n}), r = class {\n\tversion = 0;\n\tname;\n\t[t] = !0;\n\tcomputedSubs_ = /* @__PURE__ */ new Map();\n\teffectSubs_ = /* @__PURE__ */ new Set();\n\tconstructor(e) {\n\t\tthis.name = e;\n\t}\n\taddComputedSub(e) {\n\t\tlet t = new WeakRef(e);\n\t\tthis.computedSubs_.set(e, t), n.register(e, {\n\t\t\tkey: e,\n\t\t\tmap: this.computedSubs_\n\t\t}, t);\n\t}\n\tremoveComputedSub(e) {\n\t\tlet t = this.computedSubs_.get(e);\n\t\tt !== void 0 && (this.computedSubs_.delete(e), n.unregister(t));\n\t}\n\taddEffectSub(e) {\n\t\tthis.effectSubs_.add(e);\n\t}\n\tremoveEffectSub(e) {\n\t\tthis.effectSubs_.delete(e);\n\t}\n\tclearSubscribers() {\n\t\tfor (let e of this.computedSubs_.values()) n.unregister(e);\n\t\tthis.computedSubs_.clear(), this.effectSubs_.clear();\n\t}\n\thasSubscribers() {\n\t\tif (this.effectSubs_.size > 0) return !0;\n\t\tfor (let e of this.computedSubs_.values()) if (e.deref() !== void 0) return !0;\n\t\treturn !1;\n\t}\n\t*computedSubs() {\n\t\tfor (let [e, t] of this.computedSubs_) {\n\t\t\tlet r = t.deref();\n\t\t\tr === void 0 ? (this.computedSubs_.delete(e), n.unregister(t)) : yield r;\n\t\t}\n\t}\n\teffectSubs() {\n\t\treturn this.effectSubs_;\n\t}\n}, i = class extends r {\n\t[e] = !0;\n\tlastPropEpoch_ = 0;\n};\n//#endregion\nexport { i as ComputedBase, r as ReactiveBase };\n\n//# sourceMappingURL=reactive-base.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { ensureError as t } from \"./_error-utils.js\";\nimport { RippleComputedCycleError as n } from \"./errors.js\";\nimport { autoRegisterDisposal as r, getRevision as i, trackSource as a, withTracking as o } from \"./tracking.js\";\nimport { SubscriptionImpl as s } from \"./subscription.js\";\nimport { UNINITIALIZED as c } from \"./symbols.js\";\nimport { ComputedBase as l } from \"./reactive-base.js\";\n//#region src/computed.ts\nvar u = class extends l {\n\tvalue_;\n\tdirty_;\n\tcomputing_;\n\tdisposed_;\n\tdeps_;\n\tcompute_;\n\tequals_;\n\tmaxRevision_;\n\tconstructor(e, t) {\n\t\tlet { equals: n, name: r } = t ?? {};\n\t\tsuper(r), this.value_ = c, this.dirty_ = !0, this.computing_ = !1, this.disposed_ = !1, this.deps_ = [], this.maxRevision_ = -1, this.compute_ = e, this.equals_ = n === void 0 ? Object.is : (e, t) => n(e, t);\n\t}\n\tmarkDirty() {\n\t\treturn this.disposed_ || this.dirty_ ? !1 : (this.dirty_ = !0, !0);\n\t}\n\trefreshIfDirty() {\n\t\tif (!this.dirty_) return !1;\n\t\tif (i() <= this.maxRevision_) return this.dirty_ = !1, !1;\n\t\tif (this.deps_.length > 0) {\n\t\t\tlet e = !0;\n\t\t\tfor (let t of this.deps_) {\n\t\t\t\tlet n = t.source;\n\t\t\t\tif (\"refreshIfDirty\" in n && n.refreshIfDirty(), n.version !== t.version) {\n\t\t\t\t\te = !1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (e) return this.dirty_ = !1, this.maxRevision_ = i(), !1;\n\t\t}\n\t\treturn this.recompute();\n\t}\n\trunCompute(e) {\n\t\ttry {\n\t\t\treturn o({\n\t\t\t\tcomputed: this,\n\t\t\t\tdepCollector: e,\n\t\t\t\tkind: \"computed\"\n\t\t\t}, this.compute_);\n\t\t} catch (e) {\n\t\t\tthrow t(e);\n\t\t}\n\t}\n\trecompute() {\n\t\tif (this.computing_) throw new n(`computed cycle detected${this.name ? ` \"${this.name}\"` : \"\"}`);\n\t\tthis.computing_ = !0;\n\t\ttry {\n\t\t\tlet t = [];\n\t\t\te()?.compute?.({ name: this.name });\n\t\t\tlet n = this.runCompute(t);\n\t\t\treturn this.dirty_ = !1, this.maxRevision_ = i(), this.updateDeps(t), this.value_ === c || !this.equals_(this.value_, n) ? (this.value_ = n, this.version++, !0) : !1;\n\t\t} finally {\n\t\t\tthis.computing_ = !1;\n\t\t}\n\t}\n\tupdateDeps(e) {\n\t\tlet t = this.deps_;\n\t\tif (t.length === e.length && t.every((t, n) => t.source === e[n].source)) {\n\t\t\tfor (let n = 0; n < e.length; n++) t[n].version = e[n].version;\n\t\t\treturn;\n\t\t}\n\t\tlet n = new Set(t.map((e) => e.source)), r = new Set(e.map((e) => e.source));\n\t\tfor (let e of t) r.has(e.source) || e.source.removeComputedSub(this);\n\t\tfor (let t of e) n.has(t.source) || t.source.addComputedSub(this);\n\t\tthis.deps_ = e;\n\t}\n\tget value() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), a(this), this.value_);\n\t}\n\tpeek() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), this.value_);\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new s(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.refreshIfDirty(), this.addEffectSub(e), new s(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (!this.disposed_) {\n\t\t\tthis.disposed_ = !0;\n\t\t\tfor (let e of this.deps_) e.source.removeComputedSub(this);\n\t\t\tthis.deps_ = [], this.clearSubscribers(), e()?.dispose?.({\n\t\t\t\tkind: \"computed\",\n\t\t\t\tname: this.name\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, d = (e, t) => {\n\tlet n = new u(e, t);\n\treturn r(() => n.dispose()), n;\n};\n//#endregion\nexport { u as ComputedImpl, d as computed };\n\n//# sourceMappingURL=computed.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { tickRevision as t, trackSource as n } from \"./tracking.js\";\nimport { notifyNodeChange as r } from \"./scheduling.js\";\nimport { SubscriptionImpl as i } from \"./subscription.js\";\nimport { ReactiveBase as a } from \"./reactive-base.js\";\n//#region src/signal.ts\nvar o = class extends a {\n\tvalue_;\n\tequals_;\n\tdisposed_;\n\tconstructor(e, t, n) {\n\t\tsuper(n), this.value_ = e, this.equals_ = t ?? Object.is, this.disposed_ = !1;\n\t}\n\tget value() {\n\t\treturn this.disposed_ || n(this), this.value_;\n\t}\n\tset value(n) {\n\t\tif (this.disposed_ || this.equals_(this.value_, n)) return;\n\t\tlet i = this.value_;\n\t\tthis.value_ = n, this.version = t(), e()?.write?.({\n\t\t\tname: this.name,\n\t\t\tnewValue: n,\n\t\t\toldValue: i\n\t\t}), r(this);\n\t}\n\tpeek() {\n\t\treturn this.value_;\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new i(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.addEffectSub(e), new i(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tthis.disposed_ || (this.disposed_ = !0, this.clearSubscribers(), e()?.dispose?.({\n\t\t\tkind: \"signal\",\n\t\t\tname: this.name\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, s = (e, t) => new o(e, t?.equals, t?.name);\n//#endregion\nexport { o as SignalImpl, s as signal };\n\n//# sourceMappingURL=signal.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n const disposables = [\n undoStack,\n redoStack,\n pending,\n processing,\n canUndo,\n canRedo,\n historySize,\n isProcessing,\n pendingCount,\n historySnapshot,\n ];\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n\n for (const d of disposables) d.dispose();\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"qFAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE,UAAY,IAwB9C,EACN,KAAO,IAAW,CAChB,IAAI,EACA,EAAW,GAEf,IAAK,IAAM,IAAK,CAAC,GAAG,CAAQ,CAAC,CAAC,QAAQ,EACpC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,OAAS,EAAK,CACZ,AAEE,KADA,EAAa,EACF,GAEf,CAGF,GAAI,EAAU,MAAM,CACtB,EACA,IAAA,EACN,CACF,CC3DA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,CAClD,CAEA,OAAO,GAAG,EAAkC,CAC1C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAyC,CAAY,CAAC,EAGzC,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC,ECnBlDA,EAAI,KAAMC,MAAUD,EC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AM,IAAI,EAAqB,EAAU,CAAG,EAAG,CAAE,MAAO,CAAI,CAAC,CAC/D,CAEI,IAEJ,EAAU,MAAQ,EAAM,MAAM,EAAG,EAAE,EACnC,EAAU,MAAQ,CAAC,GAAG,EAAU,MAAO,CAAK,EAC9C,CAAC,CACH,CAEA,SAAS,GAAuB,CAC9B,OAAO,EAAQ,QAAS,SAAY,CAC9B,IAEJ,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EACrB,CAAC,CACH,CAEA,SAAS,GAAgB,CACvB,EAAa,GACb,EAAG,MAAM,EAET,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EAEnB,IAAK,IAAM,KAAK,EAAa,EAAE,QAAQ,CACzC,CAEA,MAAO,CACL,UACA,UAEA,QAEA,IAAI,gBAA8B,CAChC,OAAO,EAAG,MACZ,EACA,UACA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAyB,EAAgD,CAC1E,OAAO,EAAQ,SAAY,EAAM,EAAwB,CAAO,EAAG,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC1G,EAEA,cACA,kBACA,eACA,eAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,EAEA,CAAC,OAAO,UAAiB,CACvB,EAAQ,CACV,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,CACF,CACF"}
1
+ {"version":3,"file":"ledger.iife.js","names":["e","r","l","u","t","e","d","f","p","n","e","e","i","e","o","s","c"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.js","../../ripple/dist/_store.js","../../ripple/dist/_watch.js","../../ripple/dist/index.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, e as RippleError, r as RippleInfiniteLoopError };\n\n//# sourceMappingURL=errors.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleInfiniteLoopError as n } from \"./errors.js\";\n//#region src/runtime.ts\nvar r = Symbol(\"ripple.reactive\"), i = Symbol(\"ripple.signal\"), a = Symbol(\"ripple.computed\"), o = 100, s = Symbol(\"ripple.unset\"), c = class {\n\t[r] = !0;\n\tdependents = /* @__PURE__ */ new Set();\n\tname;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tsubscribe(e) {\n\t\tthis.peek();\n\t\tlet t = {\n\t\t\tdependencies: /* @__PURE__ */ new Set(),\n\t\t\tonDependencyChanged: () => this.runtime.enqueueListener(e)\n\t\t};\n\t\treturn this.dependents.add(t), () => this.dependents.delete(t);\n\t}\n\tnotify() {\n\t\tfor (let e of [...this.dependents]) e.onDependencyChanged();\n\t}\n}, l = class extends c {\n\t[i] = !0;\n\tcurrent;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.runtime.track(this), this.current;\n\t}\n\tset value(e) {\n\t\tif (this.equals(this.current, e)) return;\n\t\tlet t = this.current;\n\t\tthis.current = e, this.runtime.emit({\n\t\t\tkind: \"write\",\n\t\t\tname: this.name,\n\t\t\tnext: e,\n\t\t\tprevious: t\n\t\t}), this.runtime.propagate(() => this.notify());\n\t}\n\tpeek() {\n\t\treturn this.current;\n\t}\n}, u = class extends c {\n\t[a] = !0;\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = s;\n\tderive;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.refresh(), this.runtime.track(this), this.current;\n\t}\n\tpeek() {\n\t\treturn this.refresh(), this.current;\n\t}\n\tonDependencyChanged() {\n\t\tthis.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());\n\t}\n\tdispose() {\n\t\tthis.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());\n\t}\n\trefresh() {\n\t\tif (!this.dirty || this.disposed) return !1;\n\t\tif (this.computing) {\n\t\t\tlet t = this.name === void 0 ? \"\" : ` \"${this.name}\"`;\n\t\t\tthrow new e(`computed cycle detected${t}`);\n\t\t}\n\t\tthis.computing = !0, this.runtime.emit({\n\t\t\tkind: \"compute\",\n\t\t\tname: this.name\n\t\t});\n\t\ttry {\n\t\t\tlet e = this.runtime.collect(this, this.derive), t = this.current === s || !this.equals(this.current, e);\n\t\t\treturn this.current = e, this.dirty = !1, t;\n\t\t} finally {\n\t\t\tthis.computing = !1;\n\t\t}\n\t}\n}, d = class {\n\tdisposalController = new AbortController();\n\towned = /* @__PURE__ */ new Set();\n\tname;\n\tisDisposed = !1;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\trun(e) {\n\t\tif (this.isDisposed) throw new t(\"Cannot run a disposed scope.\");\n\t\treturn this.runtime.withScope(this, e);\n\t}\n\tdispose() {\n\t\tif (!this.isDisposed) {\n\t\t\tthis.isDisposed = !0;\n\t\t\tfor (let e of [...this.owned].reverse()) e.dispose();\n\t\t\tthis.owned.clear(), this.disposalController.abort(), this.runtime.emit({\n\t\t\t\tkind: \"dispose\",\n\t\t\t\tname: this.name,\n\t\t\t\tnode: \"scope\"\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, f = class {\n\tdependencies = /* @__PURE__ */ new Set();\n\tdisposalController = new AbortController();\n\tcleanup;\n\tisDisposed = !1;\n\towner;\n\tscheduled = !1;\n\tcallback;\n\toptions;\n\truntime;\n\tconstructor(e, t, n) {\n\t\tthis.runtime = e, this.callback = t, this.options = n;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\tonDependencyChanged() {\n\t\tif (!this.isDisposed) {\n\t\t\tif (this.options?.scheduler === \"microtask\") {\n\t\t\t\tif (this.scheduled) return;\n\t\t\t\tthis.scheduled = !0, queueMicrotask(() => {\n\t\t\t\t\tthis.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.runtime.enqueue(this);\n\t\t}\n\t}\n\trun() {\n\t\tif (this.isDisposed) return;\n\t\tthis.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({\n\t\t\tkind: \"effect\",\n\t\t\tname: this.options?.name\n\t\t});\n\t\tlet e = new d(this.runtime);\n\t\ttry {\n\t\t\tlet t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));\n\t\t\tthis.owner = e, this.cleanup = typeof t == \"function\" ? t : void 0;\n\t\t} catch (t) {\n\t\t\te.dispose(), this.runtime.report(t, {\n\t\t\t\tkind: \"effect\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({\n\t\t\tkind: \"dispose\",\n\t\t\tname: this.options?.name,\n\t\t\tnode: \"effect\"\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\trunCleanup() {\n\t\tlet e = this.cleanup;\n\t\tif (this.cleanup = void 0, e !== void 0) try {\n\t\t\te();\n\t\t} catch (e) {\n\t\t\tthis.runtime.report(e, {\n\t\t\t\tkind: \"cleanup\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n}, p = class {\n\tactiveEffectScope;\n\tactiveObserver;\n\tactiveScope;\n\tflushDepth = 0;\n\tflushing = !1;\n\tpending = /* @__PURE__ */ new Set();\n\tlisteners = /* @__PURE__ */ new Set();\n\trootScope;\n\tobserver;\n\tonError;\n\tconstructor(e) {\n\t\tthis.observer = e?.observer, this.onError = e?.onError ?? ((e) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}), this.rootScope = new d(this, \"runtime\"), this.activeScope = this.rootScope;\n\t}\n\tsignal = (e, t) => new l(this, e, t);\n\tcomputed = (e, t) => {\n\t\tlet n = new u(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n;\n\t};\n\teffect = (e, t) => {\n\t\tlet n = new f(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;\n\t};\n\tcreateScope = (e) => {\n\t\tlet t = new d(this, e);\n\t\treturn this.activeScope.owned.add(t), t;\n\t};\n\tbatch = (e) => this.propagate(e);\n\tuntrack = (e) => this.withObserver(void 0, e);\n\tdispose() {\n\t\tthis.rootScope.dispose();\n\t}\n\ttrack(e) {\n\t\tlet t = this.activeObserver;\n\t\tt?.collecting !== void 0 && t.collecting.add(e);\n\t}\n\tclearDependencies(e) {\n\t\tfor (let t of e.dependencies) t.dependents.delete(e);\n\t\te.dependencies.clear();\n\t}\n\tcollect(e, t) {\n\t\treturn this.collectWith(e, t, !1);\n\t}\n\tcollectEffect(e, t) {\n\t\treturn this.collectWith(e, t, !0);\n\t}\n\twithEffectScope(e, t) {\n\t\tlet n = this.activeEffectScope;\n\t\tthis.activeEffectScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n;\n\t\t}\n\t}\n\twithObserver(e, t) {\n\t\tlet n = this.activeObserver;\n\t\tthis.activeObserver = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeObserver = n;\n\t\t}\n\t}\n\twithScope(e, t) {\n\t\tlet n = this.activeEffectScope, r = this.activeScope;\n\t\tthis.activeEffectScope = void 0, this.activeScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n, this.activeScope = r;\n\t\t}\n\t}\n\tenqueue(e) {\n\t\tthis.pending.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tenqueueListener(e) {\n\t\tthis.listeners.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tpropagate(e) {\n\t\tthis.flushDepth++;\n\t\ttry {\n\t\t\treturn e();\n\t\t} finally {\n\t\t\tthis.flushDepth--, this.flushDepth === 0 && this.flush();\n\t\t}\n\t}\n\temit(e) {\n\t\ttry {\n\t\t\tthis.observer?.(e);\n\t\t} catch (t) {\n\t\t\tthis.report(t, {\n\t\t\t\tkind: \"observer\",\n\t\t\t\tname: e.name\n\t\t\t});\n\t\t}\n\t}\n\treport(e, t) {\n\t\ttry {\n\t\t\tthis.onError(e, t);\n\t\t} catch (e) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}\n\t}\n\tcollectWith(e, t, n) {\n\t\tlet r = this.activeObserver, i = /* @__PURE__ */ new Set();\n\t\te.collecting = i, this.activeObserver = e;\n\t\ttry {\n\t\t\tlet n = t();\n\t\t\treturn this.commitDependencies(e, i), n;\n\t\t} catch (t) {\n\t\t\tthrow n && this.commitDependencies(e, i), t;\n\t\t} finally {\n\t\t\te.collecting = void 0, this.activeObserver = r;\n\t\t}\n\t}\n\tcommitDependencies(e, t) {\n\t\tfor (let n of e.dependencies) t.has(n) || n.dependents.delete(e);\n\t\tfor (let n of t) e.dependencies.has(n) || n.dependents.add(e);\n\t\te.dependencies.clear();\n\t\tfor (let n of t) e.dependencies.add(n);\n\t}\n\tflush() {\n\t\tif (this.flushing) return;\n\t\tthis.flushing = !0;\n\t\tlet e = 0;\n\t\ttry {\n\t\t\tfor (; this.pending.size > 0 || this.listeners.size > 0;) {\n\t\t\t\tif (++e > o) throw new n(`infinite reactive flush (>${o} iterations)`);\n\t\t\t\tlet t = [...this.pending], r = [...this.listeners];\n\t\t\t\tthis.pending.clear(), this.listeners.clear();\n\t\t\t\tfor (let e of t) e.run();\n\t\t\t\tfor (let e of r) try {\n\t\t\t\t\te();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.report(e, { kind: \"listener\" });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.flushing = !1;\n\t\t}\n\t}\n}, m = (e) => typeof e == \"object\" && !!e && r in e;\n//#endregion\nexport { p as ReactiveRuntime, m as isReactive };\n\n//# sourceMappingURL=runtime.js.map","//#region src/_async.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = e.signal({ status: \"pending\" }, { name: r?.name }), a = e.signal(0), o = new AbortController(), s, c = !1, l = () => {\n\t\ta.value, s?.abort();\n\t\tlet e = i.peek(), r = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, o;\n\t\ttry {\n\t\t\to = t();\n\t\t} catch (e) {\n\t\t\ti.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tlet l = new AbortController();\n\t\ts = l, i.value = r === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: r,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(n(o, { signal: l.signal }));\n\t\t} catch (e) {\n\t\t\tu = Promise.reject(e);\n\t\t}\n\t\tu.then((e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = {\n\t\t\t\tstatus: \"success\",\n\t\t\t\tvalue: e\n\t\t\t});\n\t\t}, (e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = e.effect(() => (l(), () => s?.abort()), { name: r?.name });\n\treturn u.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0, o.abort();\n\t}, { once: !0 }), {\n\t\tget disposalSignal() {\n\t\t\treturn o.signal;\n\t\t},\n\t\tdispose: () => u.dispose(),\n\t\tget disposed() {\n\t\t\treturn c;\n\t\t},\n\t\tget name() {\n\t\t\treturn i.name;\n\t\t},\n\t\tpeek: () => i.peek(),\n\t\treload: () => {\n\t\t\tc || (a.value = a.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => i.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn i.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createResource };\n\n//# sourceMappingURL=_async.js.map","//#region src/_store.ts\nvar e = (e) => (t, n) => {\n\tlet r = e.signal(t, { name: n?.name });\n\treturn {\n\t\tget name() {\n\t\t\treturn r.name;\n\t\t},\n\t\tpeek: () => r.peek(),\n\t\tset: (e) => {\n\t\t\tr.value = e;\n\t\t},\n\t\tsubscribe: (e) => r.subscribe(e),\n\t\tupdate: (e) => {\n\t\t\tr.value = e(r.peek());\n\t\t},\n\t\tget value() {\n\t\t\treturn r.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createStore };\n\n//# sourceMappingURL=_store.js.map","//#region src/_watch.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = typeof t == \"function\" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s, c = !1, l = e.effect(() => {\n\t\tlet e = i();\n\t\tif (o) {\n\t\t\to = !1, s = e, r?.immediate && n(e, void 0), c = r?.once === !0 && r.immediate === !0;\n\t\t\treturn;\n\t\t}\n\t\tif (a(s, e)) return;\n\t\tlet t = s;\n\t\ts = e, n(e, t), r?.once && l.dispose();\n\t}, { name: r?.name });\n\treturn c && l.dispose(), l;\n};\n//#endregion\nexport { e as createWatch };\n\n//# sourceMappingURL=_watch.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleError as n, RippleInfiniteLoopError as r } from \"./errors.js\";\nimport { ReactiveRuntime as i, isReactive as a } from \"./runtime.js\";\nimport { createResource as o } from \"./_async.js\";\nimport { createStore as s } from \"./_store.js\";\nimport { createWatch as c } from \"./_watch.js\";\n//#region src/index.ts\nvar l = (e) => {\n\tlet t = new i(e), n = o(t), r = s(t);\n\treturn {\n\t\tbatch: t.batch,\n\t\tcomputed: t.computed,\n\t\tcreateScope: t.createScope,\n\t\tcreateStore: r,\n\t\tdispose: () => t.dispose(),\n\t\teffect: t.effect,\n\t\tresource: n,\n\t\tsignal: t.signal,\n\t\tuntrack: t.untrack,\n\t\twatch: c(t)\n\t};\n}, u = l(), d = u.signal, f = u.computed, p = u.effect, m = u.batch, h = u.createScope, g = u.createStore, _ = u.resource, v = u.untrack, y = u.watch;\n//#endregion\nexport { e as RippleComputedCycleError, t as RippleDisposedScopeError, n as RippleError, r as RippleInfiniteLoopError, m as batch, f as computed, l as createRipple, h as createScope, g as createStore, p as effect, a as isReactive, _ as resource, d as signal, v as untrack, y as watch };\n\n//# sourceMappingURL=index.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"qFAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE,UAAY,IAwB9C,EACN,KAAO,IAAW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EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EACrB,CAAC,CACH,CAEA,SAAS,GAAgB,CACvB,EAAa,GACb,EAAG,MAAM,EAET,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,CACrB,CAEA,MAAO,CACL,UACA,UAEA,QAEA,IAAI,gBAA8B,CAChC,OAAO,EAAG,MACZ,EACA,UACA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAyB,EAAgD,CAC1E,OAAO,EAAQ,SAAY,EAAM,EAAwB,CAAO,EAAG,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC1G,EAEA,cACA,kBACA,eACA,eAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,EAEA,CAAC,OAAO,UAAiB,CACvB,EAAQ,CACV,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,CACF,CACF"}
package/dist/ledger.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=null,o=()=>a,s=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},c=class extends s{},l=class extends s{},u=0,d=()=>++u,f=()=>u,p={scheduling:{activeDirty:`a`,batchDepth:0,dirtyWithEffectSubsA:new Set,dirtyWithEffectSubsB:new Set,pendingSubscribers:new Set},scopeCleanups:null,tracking:null},m=null,h=()=>m===null?p:m.get(),g=()=>h().scheduling,_=()=>m!==null,v=()=>h().tracking,y=(e,t)=>{if(m!==null){let n=m.get();return m.run({...n,tracking:e},t)}let n=p;p={...p,tracking:e};try{return t()}finally{p=n}},b=()=>h().scopeCleanups,x=e=>{let t=v();t?.kind===`effect`?t.cleanups.push(e):b()?.push(e)},S=e=>{let t=v();if(t!==null){if(t.sourceObserver?.(e),t.kind===`computed`)t.depCollector.push({source:e,version:e.version});else if(t.kind===`effect`){let n=t.effect;e.addEffectSub(n),t.subscriptions.add(()=>e.removeEffectSub(n)),t.deps.set(e,e.version)}}},C=e=>e instanceof Error?e:Error(`Non-Error thrown: ${String(e)}`),w=e=>{let t=[];for(let n of e)try{n()}catch(e){t.push(C(e))}return t},T=(e,t)=>{let n=w(e);if(n.length===1)throw n[0];if(n.length>0)throw AggregateError(n,t)},E=!globalThis.__RIPPLE_PROD__;function D(e){E&&console.warn(`[@vielzeug/ripple] ${e}`)}var O=!1,k=0,A=[],j=e=>e.activeDirty===`a`?e.dirtyWithEffectSubsA:e.dirtyWithEffectSubsB,M=(e,t)=>{let n=++k;for(let n of t.effectSubs())e.pendingSubscribers.add(n);for(let e of t.computedSubs())A.push(e);try{for(;A.length>0;){let t=A.pop();if(t.lastPropEpoch_!==n&&(t.lastPropEpoch_=n,t.markDirty())){t.effectSubs().size>0&&j(e).add(t);for(let e of t.computedSubs())A.push(e)}}}finally{A.length=0}},N=e=>{for(;j(e).size>0;){let t=j(e);e.activeDirty=e.activeDirty===`a`?`b`:`a`,j(e).clear();for(let n of t)if(n.hasSubscribers()&&n.refreshIfDirty()){for(let t of n.effectSubs())e.pendingSubscribers.add(t);for(let t of n.computedSubs())t.markDirty()&&t.effectSubs().size>0&&j(e).add(t)}t.clear()}},P=e=>{let t=0;for(;e.pendingSubscribers.size>0||j(e).size>0;){if(++t>100)throw new l(`infinite flush loop (> 100 iterations)`);if(j(e).size>0&&N(e),e.pendingSubscribers.size===0)continue;let n=[...e.pendingSubscribers];e.pendingSubscribers.clear(),T(n,`subscriber errors`)}},F=globalThis.process?.versions!=null,I=e=>{if(!e.hasSubscribers())return;!O&&F&&!_()&&(O=!0,D(`Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.`));let t=g();M(t,e),t.batchDepth===0&&P(t)},L=class{fn_;disposed_=!1;constructor(e){this.fn_=e}get disposed(){return this.disposed_}dispose(){if(this.disposed_)return;this.disposed_=!0;let e=this.fn_;this.fn_=null,e()}[Symbol.dispose](){this.dispose()}},R=Symbol(`ripple.is-signal`),z=Symbol(`ripple.is-computed`),B=Symbol(`ripple.uninitialized`),V=new FinalizationRegistry(({key:e,map:t})=>{t.delete(e)}),H=class{version=0;name;[R]=!0;computedSubs_=new Map;effectSubs_=new Set;constructor(e){this.name=e}addComputedSub(e){let t=new WeakRef(e);this.computedSubs_.set(e,t),V.register(e,{key:e,map:this.computedSubs_},t)}removeComputedSub(e){let t=this.computedSubs_.get(e);t!==void 0&&(this.computedSubs_.delete(e),V.unregister(t))}addEffectSub(e){this.effectSubs_.add(e)}removeEffectSub(e){this.effectSubs_.delete(e)}clearSubscribers(){for(let e of this.computedSubs_.values())V.unregister(e);this.computedSubs_.clear(),this.effectSubs_.clear()}hasSubscribers(){if(this.effectSubs_.size>0)return!0;for(let e of this.computedSubs_.values())if(e.deref()!==void 0)return!0;return!1}*computedSubs(){for(let[e,t]of this.computedSubs_){let n=t.deref();n===void 0?(this.computedSubs_.delete(e),V.unregister(t)):yield n}}effectSubs(){return this.effectSubs_}},U=class extends H{[z]=!0;lastPropEpoch_=0},W=class extends U{value_;dirty_;computing_;disposed_;deps_;compute_;equals_;maxRevision_;constructor(e,t){let{equals:n,name:r}=t??{};super(r),this.value_=B,this.dirty_=!0,this.computing_=!1,this.disposed_=!1,this.deps_=[],this.maxRevision_=-1,this.compute_=e,this.equals_=n===void 0?Object.is:(e,t)=>n(e,t)}markDirty(){return this.disposed_||this.dirty_?!1:(this.dirty_=!0,!0)}refreshIfDirty(){if(!this.dirty_)return!1;if(f()<=this.maxRevision_)return this.dirty_=!1,!1;if(this.deps_.length>0){let e=!0;for(let t of this.deps_){let n=t.source;if(`refreshIfDirty`in n&&n.refreshIfDirty(),n.version!==t.version){e=!1;break}}if(e)return this.dirty_=!1,this.maxRevision_=f(),!1}return this.recompute()}runCompute(e){try{return y({computed:this,depCollector:e,kind:`computed`},this.compute_)}catch(e){throw C(e)}}recompute(){if(this.computing_)throw new c(`computed cycle detected${this.name?` "${this.name}"`:``}`);this.computing_=!0;try{let e=[];o()?.compute?.({name:this.name});let t=this.runCompute(e);return this.dirty_=!1,this.maxRevision_=f(),this.updateDeps(e),this.value_===B||!this.equals_(this.value_,t)?(this.value_=t,this.version++,!0):!1}finally{this.computing_=!1}}updateDeps(e){let t=this.deps_;if(t.length===e.length&&t.every((t,n)=>t.source===e[n].source)){for(let n=0;n<e.length;n++)t[n].version=e[n].version;return}let n=new Set(t.map(e=>e.source)),r=new Set(e.map(e=>e.source));for(let e of t)r.has(e.source)||e.source.removeComputedSub(this);for(let t of e)n.has(t.source)||t.source.addComputedSub(this);this.deps_=e}get value(){return this.disposed_?this.value_===B?void 0:this.value_:(this.refreshIfDirty(),S(this),this.value_)}peek(){return this.disposed_?this.value_===B?void 0:this.value_:(this.refreshIfDirty(),this.value_)}subscribe=e=>{if(this.disposed_){let e=new L(()=>{});return e.dispose(),e}return this.refreshIfDirty(),this.addEffectSub(e),new L(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){if(!this.disposed_){this.disposed_=!0;for(let e of this.deps_)e.source.removeComputedSub(this);this.deps_=[],this.clearSubscribers(),o()?.dispose?.({kind:`computed`,name:this.name})}}[Symbol.dispose](){this.dispose()}},G=(e,t)=>{let n=new W(e,t);return x(()=>n.dispose()),n},K=class extends H{value_;equals_;disposed_;constructor(e,t,n){super(n),this.value_=e,this.equals_=t??Object.is,this.disposed_=!1}get value(){return this.disposed_||S(this),this.value_}set value(e){if(this.disposed_||this.equals_(this.value_,e))return;let t=this.value_;this.value_=e,this.version=d(),o()?.write?.({name:this.name,newValue:e,oldValue:t}),I(this)}peek(){return this.value_}subscribe=e=>{if(this.disposed_){let e=new L(()=>{});return e.dispose(),e}return this.addEffectSub(e),new L(()=>{this.removeEffectSub(e)})};get disposed(){return this.disposed_}dispose(){this.disposed_||(this.disposed_=!0,this.clearSubscribers(),o()?.dispose?.({kind:`signal`,name:this.name}))}[Symbol.dispose](){this.dispose()}},q=(e,t)=>new K(e,t?.equals,t?.name),J=!globalThis.__LEDGER_PROD__;function Y(e){J&&console.warn(`[@vielzeug/ledger] ${e}`)}function X(e){return e instanceof Error?e.message:String(e)}function Z(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function Q(e={}){let{maxHistory:t=100,onRollbackError:a}=e;t<1&&Y(`maxHistory must be >= 1; history tracking is disabled for this ledger.`);let o=q([],{name:`ledger:undoStack`}),s=q([],{name:`ledger:redoStack`}),c=q(0,{name:`ledger:pending`}),l=q(!1,{name:`ledger:processing`}),u=G(()=>o.value.length>0,{name:`ledger:canUndo`}),d=G(()=>s.value.length>0,{name:`ledger:canRedo`}),f=G(()=>o.value.length,{name:`ledger:historySize`}),p=G(()=>l.value,{name:`ledger:isProcessing`}),m=G(()=>c.value,{name:`ledger:pendingCount`}),h=G(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=[o,s,c,l,u,d,f,p,m,h],_=!1,v=Promise.resolve(),y=new AbortController;function b(e){return e?AbortSignal.any([e,y.signal]):y.signal}function x(e,t){if(_)return Promise.reject(new n(`Cannot call ${e}() on a disposed ledger.`));c.value++;let r=v.then(t).finally(()=>{_||c.value--});return v=r.catch(()=>{}),r}async function S(e){l.value=!0;try{await e()}finally{_||(l.value=!1)}}async function C(e,n){await S(async()=>{try{await e.execute(n)}catch(e){throw new r(X(e),{cause:e})}if(_)return;let i=[...o.value,e];i.length>t&&i.shift(),o.value=i,s.value=[]})}async function w(e){let t=o.value;if(t.length===0)return;let n=t[t.length-1];await S(async()=>{if(n.rollback)try{await n.rollback(e)}catch(e){Y(`rollback() threw for "${n.meta.label??`(unlabelled)`}". Stack position unchanged.`),a?.(new i(X(e),{cause:e}),n.meta);return}_||(o.value=t.slice(0,-1),s.value=[...s.value,n])})}async function T(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await S(async()=>{try{await n.execute(e)}catch(e){throw new r(X(e),{cause:e})}_||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function E(){return x(`clear`,async()=>{_||(o.value=[],s.value=[])})}function D(){_=!0,y.abort(),o.value=[],s.value=[];for(let e of g)e.dispose()}return{canRedo:d,canUndo:u,clear:E,get disposalSignal(){return y.signal},dispose:D,get disposed(){return _},do(e,t){return x(`do`,()=>C(Z(e),b(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return x(`redo`,()=>T(b(e?.signal)))},[Symbol.dispose](){D()},undo(e){return x(`undo`,()=>w(b(e?.signal)))}}}export{n as LedgerDisposedError,t as LedgerError,r as LedgerExecutionError,i as LedgerRollbackError,e as compose,Q as createLedger};
1
+ function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},o=class extends a{},s=class extends a{},c=class extends a{},l=Symbol(`ripple.reactive`),u=Symbol(`ripple.signal`),d=Symbol(`ripple.computed`),f=100,p=Symbol(`ripple.unset`),m=class{[l]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.peek();let t={dependencies:new Set,onDependencyChanged:()=>this.runtime.enqueueListener(e)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},h=class extends m{[u]=!0;current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({kind:`write`,name:this.name,next:e,previous:t}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}},g=class extends m{[d]=!0;dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=p;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.refresh(),this.runtime.track(this),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){this.disposed||(this.dirty||=!0,this.dependents.size>0&&this.refresh()&&this.notify())}dispose(){this.disposed||(this.disposed=!0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing)throw new o(`computed cycle detected${this.name===void 0?``:` "${this.name}"`}`);this.computing=!0,this.runtime.emit({kind:`compute`,name:this.name});try{let e=this.runtime.collect(this,this.derive),t=this.current===p||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},_=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}run(e){if(this.isDisposed)throw new s(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.name,node:`scope`})}}[Symbol.dispose](){this.dispose()}},v=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;owner;scheduled=!1;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}onDependencyChanged(){if(!this.isDisposed){if(this.options?.scheduler===`microtask`){if(this.scheduled)return;this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.isDisposed||this.runtime.enqueue(this)});return}this.runtime.enqueue(this)}}run(){if(this.isDisposed)return;this.owner?.dispose(),this.owner=void 0,this.runCleanup(),this.runtime.emit({kind:`effect`,name:this.options?.name});let e=new _(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.owner=e,this.cleanup=typeof t==`function`?t:void 0}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.owner?.dispose(),this.owner=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.options?.name,node:`effect`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},y=class{activeEffectScope;activeObserver;activeScope;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;observer;onError;constructor(e){this.observer=e?.observer,this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new _(this,`runtime`),this.activeScope=this.rootScope}signal=(e,t)=>new h(this,e,t);computed=(e,t)=>{let n=new g(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{let n=new v(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{let t=new _(this,e);return this.activeScope.owned.add(t),t};batch=e=>this.propagate(e);untrack=e=>this.withObserver(void 0,e);dispose(){this.rootScope.dispose()}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,!1)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){try{this.observer?.(e)}catch(t){this.report(t,{kind:`observer`,name:e.name})}}report(e,t){try{this.onError(e,t)}catch(e){queueMicrotask(()=>{throw e})}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>f)throw new c(`infinite reactive flush (>${f} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},b=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o=new AbortController,s,c=!1,l=()=>{a.value,s?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,o;try{o=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;s=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(o,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!c&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!c&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},u=e.effect(()=>(l(),()=>s?.abort()),{name:r?.name});return u.disposalSignal.addEventListener(`abort`,()=>{c=!0,o.abort()},{once:!0}),{get disposalSignal(){return o.signal},dispose:()=>u.dispose(),get disposed(){return c},get name(){return i.name},peek:()=>i.peek(),reload:()=>{c||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}}},x=e=>(t,n)=>{let r=e.signal(t,{name:n?.name});return{get name(){return r.name},peek:()=>r.peek(),set:e=>{r.value=e},subscribe:e=>r.subscribe(e),update:e=>{r.value=e(r.peek())},get value(){return r.value}}},S=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s,c=!1,l=e.effect(()=>{let e=i();if(o){o=!1,s=e,r?.immediate&&n(e,void 0),c=r?.once===!0&&r.immediate===!0;return}if(a(s,e))return;let t=s;s=e,n(e,t),r?.once&&l.dispose()},{name:r?.name});return c&&l.dispose(),l},C=(e=>{let t=new y(e),n=b(t),r=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,createStore:r,dispose:()=>t.dispose(),effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal,T=C.computed;C.effect,C.batch,C.createScope,C.createStore,C.resource,C.untrack,C.watch;function E(e){return e instanceof Error?e.message:String(e)}function D(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function O(e={}){let{maxHistory:t=100,onRollbackError:a}=e,o=w([],{name:`ledger:undoStack`}),s=w([],{name:`ledger:redoStack`}),c=w(0,{name:`ledger:pending`}),l=w(!1,{name:`ledger:processing`}),u=T(()=>o.value.length>0,{name:`ledger:canUndo`}),d=T(()=>s.value.length>0,{name:`ledger:canRedo`}),f=T(()=>o.value.length,{name:`ledger:historySize`}),p=T(()=>l.value,{name:`ledger:isProcessing`}),m=T(()=>c.value,{name:`ledger:pendingCount`}),h=T(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=!1,_=Promise.resolve(),v=new AbortController;function y(e){return e?AbortSignal.any([e,v.signal]):v.signal}function b(e,t){if(g)return Promise.reject(new n(`Cannot call ${e}() on a disposed ledger.`));c.value++;let r=_.then(t).finally(()=>{g||c.value--});return _=r.catch(()=>{}),r}async function x(e){l.value=!0;try{await e()}finally{g||(l.value=!1)}}async function S(e,n){await x(async()=>{try{await e.execute(n)}catch(e){throw new r(E(e),{cause:e})}if(g)return;let i=[...o.value,e];i.length>t&&i.shift(),o.value=i,s.value=[]})}async function C(e){let t=o.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{if(n.rollback)try{await n.rollback(e)}catch(e){`${n.meta.label??`(unlabelled)`}`,a?.(new i(E(e),{cause:e}),n.meta);return}g||(o.value=t.slice(0,-1),s.value=[...s.value,n])})}async function O(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{try{await n.execute(e)}catch(e){throw new r(E(e),{cause:e})}g||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function k(){return b(`clear`,async()=>{g||(o.value=[],s.value=[])})}function A(){g=!0,v.abort(),o.value=[],s.value=[]}return{canRedo:d,canUndo:u,clear:k,get disposalSignal(){return v.signal},dispose:A,get disposed(){return g},do(e,t){return b(`do`,()=>S(D(e),y(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return b(`redo`,()=>O(y(e?.signal)))},[Symbol.dispose](){A()},undo(e){return b(`undo`,()=>C(y(e?.signal)))}}}export{n as LedgerDisposedError,t as LedgerError,r as LedgerExecutionError,i as LedgerRollbackError,e as compose,O as createLedger};
2
2
  //# sourceMappingURL=ledger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.js","names":["e","t","n","e","t","n","r","i","a","o","e","t","n","r","i","a","o","s","c","l","u","d","f","p","m","e","t","n","r","e","t","o","s","u","d","t","e","i","n","r","e","t","n","r","t","e","l","c","i","o","t","n","a","s","e","r","a","n","t","e","r","i"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/devtools-hook.js","../../ripple/dist/errors.js","../../ripple/dist/tracking.js","../../ripple/dist/_error-utils.js","../../ripple/dist/_dev.js","../../ripple/dist/scheduling.js","../../ripple/dist/subscription.js","../../ripple/dist/symbols.js","../../ripple/dist/reactive-base.js","../../ripple/dist/computed.js","../../ripple/dist/signal.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/devtools-hook.ts\nvar e = null, t = () => e, n = (t) => {\n\te = t;\n};\n//#endregion\nexport { t as getDevToolsHook, n as setDevToolsHook };\n\n//# sourceMappingURL=devtools-hook.js.map","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, r as RippleEnvironmentError, e as RippleError, i as RippleInfiniteLoopError, a as RippleInvalidCleanupError, o as RippleInvalidStoreError };\n\n//# sourceMappingURL=errors.js.map","//#region src/tracking.ts\nvar e = 0, t = () => ++e, n = () => e, r = () => ({\n\tactiveDirty: \"a\",\n\tbatchDepth: 0,\n\tdirtyWithEffectSubsA: /* @__PURE__ */ new Set(),\n\tdirtyWithEffectSubsB: /* @__PURE__ */ new Set(),\n\tpendingSubscribers: /* @__PURE__ */ new Set()\n}), i = {\n\tscheduling: r(),\n\tscopeCleanups: null,\n\ttracking: null\n}, a = null, o = () => a === null ? i : a.get(), s = () => o().scheduling, c = () => a !== null, l = () => o().tracking, u = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\ttracking: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\ttracking: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, d = (e, t) => {\n\tif (a !== null) {\n\t\tlet n = a.get();\n\t\treturn a.run({\n\t\t\t...n,\n\t\t\tscopeCleanups: e\n\t\t}, t);\n\t}\n\tlet n = i;\n\ti = {\n\t\t...i,\n\t\tscopeCleanups: e\n\t};\n\ttry {\n\t\treturn t();\n\t} finally {\n\t\ti = n;\n\t}\n}, f = () => o().scopeCleanups, p = (e) => {\n\tlet t = l();\n\tt?.kind === \"effect\" ? t.cleanups.push(e) : f()?.push(e);\n}, m = (e) => {\n\tlet t = a;\n\treturn a = e, t;\n}, h = (e, t) => {\n\tlet n = l();\n\treturn n === null ? t() : u({\n\t\t...n,\n\t\tsourceObserver: e\n\t}, t);\n}, g = (e) => u(null, e), _ = (e) => {\n\tlet t = l();\n\tif (t !== null) {\n\t\tif (t.sourceObserver?.(e), t.kind === \"computed\") t.depCollector.push({\n\t\t\tsource: e,\n\t\t\tversion: e.version\n\t\t});\n\t\telse if (t.kind === \"effect\") {\n\t\t\tlet n = t.effect;\n\t\t\te.addEffectSub(n), t.subscriptions.add(() => e.removeEffectSub(n)), t.deps.set(e, e.version);\n\t\t}\n\t}\n};\n//#endregion\nexport { m as _installContextHook, p as autoRegisterDisposal, r as createSchedulingState, n as getRevision, s as getSchedulingState, f as getScopeCleanups, l as getTracking, c as hasContextHook, t as tickRevision, _ as trackSource, g as untrack, d as withScopeCleanups, h as withSourceObserver, u as withTracking };\n\n//# sourceMappingURL=tracking.js.map","//#region src/_error-utils.ts\nvar e = (e) => e instanceof Error ? e : /* @__PURE__ */ Error(`Non-Error thrown: ${String(e)}`), t = (t) => {\n\tlet n = [];\n\tfor (let r of t) try {\n\t\tr();\n\t} catch (t) {\n\t\tn.push(e(t));\n\t}\n\treturn n;\n}, n = (e, n) => {\n\tlet r = t(e);\n\tif (r.length === 1) throw r[0];\n\tif (r.length > 0) throw AggregateError(r, n);\n}, r = (t, n, r) => {\n\tthrow n.length === 0 ? t : AggregateError([e(t), ...n], r, { cause: e(t) });\n};\n//#endregion\nexport { t as collectErrors, e as ensureError, r as rethrowWith, n as runAll };\n\n//# sourceMappingURL=_error-utils.js.map","//#region src/_dev.ts\nvar e = !globalThis.__RIPPLE_PROD__;\nfunction t(t) {\n\te && console.warn(`[@vielzeug/ripple] ${t}`);\n}\n//#endregion\nexport { t as warn };\n\n//# sourceMappingURL=_dev.js.map","import { runAll as e } from \"./_error-utils.js\";\nimport { RippleInfiniteLoopError as t } from \"./errors.js\";\nimport { warn as n } from \"./_dev.js\";\nimport { getSchedulingState as r, hasContextHook as i } from \"./tracking.js\";\nvar a = !1, o = 0, s = [], c = (e) => e.activeDirty === \"a\" ? e.dirtyWithEffectSubsA : e.dirtyWithEffectSubsB, l = (e, t) => {\n\tlet n = ++o;\n\tfor (let n of t.effectSubs()) e.pendingSubscribers.add(n);\n\tfor (let e of t.computedSubs()) s.push(e);\n\ttry {\n\t\tfor (; s.length > 0;) {\n\t\t\tlet t = s.pop();\n\t\t\tif (t.lastPropEpoch_ !== n && (t.lastPropEpoch_ = n, t.markDirty())) {\n\t\t\t\tt.effectSubs().size > 0 && c(e).add(t);\n\t\t\t\tfor (let e of t.computedSubs()) s.push(e);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ts.length = 0;\n\t}\n}, u = (e) => {\n\tfor (; c(e).size > 0;) {\n\t\tlet t = c(e);\n\t\te.activeDirty = e.activeDirty === \"a\" ? \"b\" : \"a\", c(e).clear();\n\t\tfor (let n of t) if (n.hasSubscribers() && n.refreshIfDirty()) {\n\t\t\tfor (let t of n.effectSubs()) e.pendingSubscribers.add(t);\n\t\t\tfor (let t of n.computedSubs()) t.markDirty() && t.effectSubs().size > 0 && c(e).add(t);\n\t\t}\n\t\tt.clear();\n\t}\n}, d = (n) => {\n\tlet r = 0;\n\tfor (; n.pendingSubscribers.size > 0 || c(n).size > 0;) {\n\t\tif (++r > 100) throw new t(\"infinite flush loop (> 100 iterations)\");\n\t\tif (c(n).size > 0 && u(n), n.pendingSubscribers.size === 0) continue;\n\t\tlet i = [...n.pendingSubscribers];\n\t\tn.pendingSubscribers.clear(), e(i, \"subscriber errors\");\n\t}\n}, f = globalThis.process?.versions != null, p = (e) => {\n\tif (!e.hasSubscribers()) return;\n\t!a && f && !i() && (a = !0, n(\"Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.\"));\n\tlet t = r();\n\tl(t, e), t.batchDepth === 0 && d(t);\n}, m = (e) => {\n\tlet t = r();\n\tt.batchDepth++;\n\tlet n;\n\ttry {\n\t\tn = e();\n\t} catch (e) {\n\t\tthrow t.batchDepth--, t.batchDepth === 0 && (t.pendingSubscribers.clear(), t.dirtyWithEffectSubsA.clear(), t.dirtyWithEffectSubsB.clear()), e;\n\t}\n\treturn t.batchDepth--, t.batchDepth === 0 && d(t), n;\n};\n//#endregion\nexport { m as batch, p as notifyNodeChange };\n\n//# sourceMappingURL=scheduling.js.map","//#region src/subscription.ts\nvar e = class {\n\tfn_;\n\tdisposed_ = !1;\n\tconstructor(e) {\n\t\tthis.fn_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (this.disposed_) return;\n\t\tthis.disposed_ = !0;\n\t\tlet e = this.fn_;\n\t\tthis.fn_ = null, e();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, t = class {\n\tawaitDone_;\n\tgetCurrentRun_;\n\tsyncStop_;\n\tasyncDisposePromise_ = null;\n\tconstructor(e, t, n) {\n\t\tthis.awaitDone_ = t, this.getCurrentRun_ = n, this.syncStop_ = e;\n\t}\n\tget disposed() {\n\t\treturn this.syncStop_.disposed;\n\t}\n\tdispose() {\n\t\tthis.syncStop_.dispose();\n\t}\n\trun() {\n\t\treturn this.getCurrentRun_() ?? Promise.resolve();\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\t[Symbol.asyncDispose]() {\n\t\treturn this.asyncDisposePromise_ === null ? (this.dispose(), this.asyncDisposePromise_ = this.awaitDone_(), this.asyncDisposePromise_) : this.asyncDisposePromise_;\n\t}\n};\n//#endregion\nexport { t as AsyncSubscriptionImpl, e as SubscriptionImpl };\n\n//# sourceMappingURL=subscription.js.map","//#region src/symbols.ts\nvar e = Symbol(\"ripple.is-signal\"), t = Symbol(\"ripple.is-computed\"), n = Symbol(\"ripple.is-store\"), r = Symbol(\"ripple.uninitialized\");\n//#endregion\nexport { t as IS_COMPUTED, e as IS_SIGNAL, n as IS_STORE, r as UNINITIALIZED };\n\n//# sourceMappingURL=symbols.js.map","import { IS_COMPUTED as e, IS_SIGNAL as t } from \"./symbols.js\";\n//#region src/reactive-base.ts\nvar n = new FinalizationRegistry(({ key: e, map: t }) => {\n\tt.delete(e);\n}), r = class {\n\tversion = 0;\n\tname;\n\t[t] = !0;\n\tcomputedSubs_ = /* @__PURE__ */ new Map();\n\teffectSubs_ = /* @__PURE__ */ new Set();\n\tconstructor(e) {\n\t\tthis.name = e;\n\t}\n\taddComputedSub(e) {\n\t\tlet t = new WeakRef(e);\n\t\tthis.computedSubs_.set(e, t), n.register(e, {\n\t\t\tkey: e,\n\t\t\tmap: this.computedSubs_\n\t\t}, t);\n\t}\n\tremoveComputedSub(e) {\n\t\tlet t = this.computedSubs_.get(e);\n\t\tt !== void 0 && (this.computedSubs_.delete(e), n.unregister(t));\n\t}\n\taddEffectSub(e) {\n\t\tthis.effectSubs_.add(e);\n\t}\n\tremoveEffectSub(e) {\n\t\tthis.effectSubs_.delete(e);\n\t}\n\tclearSubscribers() {\n\t\tfor (let e of this.computedSubs_.values()) n.unregister(e);\n\t\tthis.computedSubs_.clear(), this.effectSubs_.clear();\n\t}\n\thasSubscribers() {\n\t\tif (this.effectSubs_.size > 0) return !0;\n\t\tfor (let e of this.computedSubs_.values()) if (e.deref() !== void 0) return !0;\n\t\treturn !1;\n\t}\n\t*computedSubs() {\n\t\tfor (let [e, t] of this.computedSubs_) {\n\t\t\tlet r = t.deref();\n\t\t\tr === void 0 ? (this.computedSubs_.delete(e), n.unregister(t)) : yield r;\n\t\t}\n\t}\n\teffectSubs() {\n\t\treturn this.effectSubs_;\n\t}\n}, i = class extends r {\n\t[e] = !0;\n\tlastPropEpoch_ = 0;\n};\n//#endregion\nexport { i as ComputedBase, r as ReactiveBase };\n\n//# sourceMappingURL=reactive-base.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { ensureError as t } from \"./_error-utils.js\";\nimport { RippleComputedCycleError as n } from \"./errors.js\";\nimport { autoRegisterDisposal as r, getRevision as i, trackSource as a, withTracking as o } from \"./tracking.js\";\nimport { SubscriptionImpl as s } from \"./subscription.js\";\nimport { UNINITIALIZED as c } from \"./symbols.js\";\nimport { ComputedBase as l } from \"./reactive-base.js\";\n//#region src/computed.ts\nvar u = class extends l {\n\tvalue_;\n\tdirty_;\n\tcomputing_;\n\tdisposed_;\n\tdeps_;\n\tcompute_;\n\tequals_;\n\tmaxRevision_;\n\tconstructor(e, t) {\n\t\tlet { equals: n, name: r } = t ?? {};\n\t\tsuper(r), this.value_ = c, this.dirty_ = !0, this.computing_ = !1, this.disposed_ = !1, this.deps_ = [], this.maxRevision_ = -1, this.compute_ = e, this.equals_ = n === void 0 ? Object.is : (e, t) => n(e, t);\n\t}\n\tmarkDirty() {\n\t\treturn this.disposed_ || this.dirty_ ? !1 : (this.dirty_ = !0, !0);\n\t}\n\trefreshIfDirty() {\n\t\tif (!this.dirty_) return !1;\n\t\tif (i() <= this.maxRevision_) return this.dirty_ = !1, !1;\n\t\tif (this.deps_.length > 0) {\n\t\t\tlet e = !0;\n\t\t\tfor (let t of this.deps_) {\n\t\t\t\tlet n = t.source;\n\t\t\t\tif (\"refreshIfDirty\" in n && n.refreshIfDirty(), n.version !== t.version) {\n\t\t\t\t\te = !1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (e) return this.dirty_ = !1, this.maxRevision_ = i(), !1;\n\t\t}\n\t\treturn this.recompute();\n\t}\n\trunCompute(e) {\n\t\ttry {\n\t\t\treturn o({\n\t\t\t\tcomputed: this,\n\t\t\t\tdepCollector: e,\n\t\t\t\tkind: \"computed\"\n\t\t\t}, this.compute_);\n\t\t} catch (e) {\n\t\t\tthrow t(e);\n\t\t}\n\t}\n\trecompute() {\n\t\tif (this.computing_) throw new n(`computed cycle detected${this.name ? ` \"${this.name}\"` : \"\"}`);\n\t\tthis.computing_ = !0;\n\t\ttry {\n\t\t\tlet t = [];\n\t\t\te()?.compute?.({ name: this.name });\n\t\t\tlet n = this.runCompute(t);\n\t\t\treturn this.dirty_ = !1, this.maxRevision_ = i(), this.updateDeps(t), this.value_ === c || !this.equals_(this.value_, n) ? (this.value_ = n, this.version++, !0) : !1;\n\t\t} finally {\n\t\t\tthis.computing_ = !1;\n\t\t}\n\t}\n\tupdateDeps(e) {\n\t\tlet t = this.deps_;\n\t\tif (t.length === e.length && t.every((t, n) => t.source === e[n].source)) {\n\t\t\tfor (let n = 0; n < e.length; n++) t[n].version = e[n].version;\n\t\t\treturn;\n\t\t}\n\t\tlet n = new Set(t.map((e) => e.source)), r = new Set(e.map((e) => e.source));\n\t\tfor (let e of t) r.has(e.source) || e.source.removeComputedSub(this);\n\t\tfor (let t of e) n.has(t.source) || t.source.addComputedSub(this);\n\t\tthis.deps_ = e;\n\t}\n\tget value() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), a(this), this.value_);\n\t}\n\tpeek() {\n\t\treturn this.disposed_ ? this.value_ === c ? void 0 : this.value_ : (this.refreshIfDirty(), this.value_);\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new s(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.refreshIfDirty(), this.addEffectSub(e), new s(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tif (!this.disposed_) {\n\t\t\tthis.disposed_ = !0;\n\t\t\tfor (let e of this.deps_) e.source.removeComputedSub(this);\n\t\t\tthis.deps_ = [], this.clearSubscribers(), e()?.dispose?.({\n\t\t\t\tkind: \"computed\",\n\t\t\t\tname: this.name\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, d = (e, t) => {\n\tlet n = new u(e, t);\n\treturn r(() => n.dispose()), n;\n};\n//#endregion\nexport { u as ComputedImpl, d as computed };\n\n//# sourceMappingURL=computed.js.map","import { getDevToolsHook as e } from \"./devtools-hook.js\";\nimport { tickRevision as t, trackSource as n } from \"./tracking.js\";\nimport { notifyNodeChange as r } from \"./scheduling.js\";\nimport { SubscriptionImpl as i } from \"./subscription.js\";\nimport { ReactiveBase as a } from \"./reactive-base.js\";\n//#region src/signal.ts\nvar o = class extends a {\n\tvalue_;\n\tequals_;\n\tdisposed_;\n\tconstructor(e, t, n) {\n\t\tsuper(n), this.value_ = e, this.equals_ = t ?? Object.is, this.disposed_ = !1;\n\t}\n\tget value() {\n\t\treturn this.disposed_ || n(this), this.value_;\n\t}\n\tset value(n) {\n\t\tif (this.disposed_ || this.equals_(this.value_, n)) return;\n\t\tlet i = this.value_;\n\t\tthis.value_ = n, this.version = t(), e()?.write?.({\n\t\t\tname: this.name,\n\t\t\tnewValue: n,\n\t\t\toldValue: i\n\t\t}), r(this);\n\t}\n\tpeek() {\n\t\treturn this.value_;\n\t}\n\tsubscribe = (e) => {\n\t\tif (this.disposed_) {\n\t\t\tlet e = new i(() => {});\n\t\t\treturn e.dispose(), e;\n\t\t}\n\t\treturn this.addEffectSub(e), new i(() => {\n\t\t\tthis.removeEffectSub(e);\n\t\t});\n\t};\n\tget disposed() {\n\t\treturn this.disposed_;\n\t}\n\tdispose() {\n\t\tthis.disposed_ || (this.disposed_ = !0, this.clearSubscribers(), e()?.dispose?.({\n\t\t\tkind: \"signal\",\n\t\t\tname: this.name\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, s = (e, t) => new o(e, t?.equals, t?.name);\n//#endregion\nexport { o as SignalImpl, s as signal };\n\n//# sourceMappingURL=signal.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n const disposables = [\n undoStack,\n redoStack,\n pending,\n processing,\n canUndo,\n canRedo,\n historySize,\n isProcessing,\n pendingCount,\n historySnapshot,\n ];\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n\n for (const d of disposables) d.dispose();\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"AAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE,UAAY,IAwB9C,EACN,KAAO,IAAW,CAChB,IAAI,EACA,EAAW,GAEf,IAAK,IAAM,IAAK,CAAC,GAAG,CAAQ,CAAC,CAAC,QAAQ,EACpC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,OAAS,EAAK,CACZ,AAEE,KADA,EAAa,EACF,GAEf,CAGF,GAAI,EAAU,MAAM,CACtB,EACA,IAAA,EACN,CACF,CC3DA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAA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ACF,CACF"}
1
+ {"version":3,"file":"ledger.js","names":["e","r","l","u","t","e","d","f","p","n","e","e","i","e","o","s","c"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.js","../../ripple/dist/_store.js","../../ripple/dist/_watch.js","../../ripple/dist/index.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, e as RippleError, r as RippleInfiniteLoopError };\n\n//# sourceMappingURL=errors.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleInfiniteLoopError as n } from \"./errors.js\";\n//#region src/runtime.ts\nvar r = Symbol(\"ripple.reactive\"), i = Symbol(\"ripple.signal\"), a = Symbol(\"ripple.computed\"), o = 100, s = Symbol(\"ripple.unset\"), c = class {\n\t[r] = !0;\n\tdependents = /* @__PURE__ */ new Set();\n\tname;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tsubscribe(e) {\n\t\tthis.peek();\n\t\tlet t = {\n\t\t\tdependencies: /* @__PURE__ */ new Set(),\n\t\t\tonDependencyChanged: () => this.runtime.enqueueListener(e)\n\t\t};\n\t\treturn this.dependents.add(t), () => this.dependents.delete(t);\n\t}\n\tnotify() {\n\t\tfor (let e of [...this.dependents]) e.onDependencyChanged();\n\t}\n}, l = class extends c {\n\t[i] = !0;\n\tcurrent;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.runtime.track(this), this.current;\n\t}\n\tset value(e) {\n\t\tif (this.equals(this.current, e)) return;\n\t\tlet t = this.current;\n\t\tthis.current = e, this.runtime.emit({\n\t\t\tkind: \"write\",\n\t\t\tname: this.name,\n\t\t\tnext: e,\n\t\t\tprevious: t\n\t\t}), this.runtime.propagate(() => this.notify());\n\t}\n\tpeek() {\n\t\treturn this.current;\n\t}\n}, u = class extends c {\n\t[a] = !0;\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = s;\n\tderive;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.refresh(), this.runtime.track(this), this.current;\n\t}\n\tpeek() {\n\t\treturn this.refresh(), this.current;\n\t}\n\tonDependencyChanged() {\n\t\tthis.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());\n\t}\n\tdispose() {\n\t\tthis.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());\n\t}\n\trefresh() {\n\t\tif (!this.dirty || this.disposed) return !1;\n\t\tif (this.computing) {\n\t\t\tlet t = this.name === void 0 ? \"\" : ` \"${this.name}\"`;\n\t\t\tthrow new e(`computed cycle detected${t}`);\n\t\t}\n\t\tthis.computing = !0, this.runtime.emit({\n\t\t\tkind: \"compute\",\n\t\t\tname: this.name\n\t\t});\n\t\ttry {\n\t\t\tlet e = this.runtime.collect(this, this.derive), t = this.current === s || !this.equals(this.current, e);\n\t\t\treturn this.current = e, this.dirty = !1, t;\n\t\t} finally {\n\t\t\tthis.computing = !1;\n\t\t}\n\t}\n}, d = class {\n\tdisposalController = new AbortController();\n\towned = /* @__PURE__ */ new Set();\n\tname;\n\tisDisposed = !1;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\trun(e) {\n\t\tif (this.isDisposed) throw new t(\"Cannot run a disposed scope.\");\n\t\treturn this.runtime.withScope(this, e);\n\t}\n\tdispose() {\n\t\tif (!this.isDisposed) {\n\t\t\tthis.isDisposed = !0;\n\t\t\tfor (let e of [...this.owned].reverse()) e.dispose();\n\t\t\tthis.owned.clear(), this.disposalController.abort(), this.runtime.emit({\n\t\t\t\tkind: \"dispose\",\n\t\t\t\tname: this.name,\n\t\t\t\tnode: \"scope\"\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, f = class {\n\tdependencies = /* @__PURE__ */ new Set();\n\tdisposalController = new AbortController();\n\tcleanup;\n\tisDisposed = !1;\n\towner;\n\tscheduled = !1;\n\tcallback;\n\toptions;\n\truntime;\n\tconstructor(e, t, n) {\n\t\tthis.runtime = e, this.callback = t, this.options = n;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\tonDependencyChanged() {\n\t\tif (!this.isDisposed) {\n\t\t\tif (this.options?.scheduler === \"microtask\") {\n\t\t\t\tif (this.scheduled) return;\n\t\t\t\tthis.scheduled = !0, queueMicrotask(() => {\n\t\t\t\t\tthis.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.runtime.enqueue(this);\n\t\t}\n\t}\n\trun() {\n\t\tif (this.isDisposed) return;\n\t\tthis.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({\n\t\t\tkind: \"effect\",\n\t\t\tname: this.options?.name\n\t\t});\n\t\tlet e = new d(this.runtime);\n\t\ttry {\n\t\t\tlet t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));\n\t\t\tthis.owner = e, this.cleanup = typeof t == \"function\" ? t : void 0;\n\t\t} catch (t) {\n\t\t\te.dispose(), this.runtime.report(t, {\n\t\t\t\tkind: \"effect\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({\n\t\t\tkind: \"dispose\",\n\t\t\tname: this.options?.name,\n\t\t\tnode: \"effect\"\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\trunCleanup() {\n\t\tlet e = this.cleanup;\n\t\tif (this.cleanup = void 0, e !== void 0) try {\n\t\t\te();\n\t\t} catch (e) {\n\t\t\tthis.runtime.report(e, {\n\t\t\t\tkind: \"cleanup\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n}, p = class {\n\tactiveEffectScope;\n\tactiveObserver;\n\tactiveScope;\n\tflushDepth = 0;\n\tflushing = !1;\n\tpending = /* @__PURE__ */ new Set();\n\tlisteners = /* @__PURE__ */ new Set();\n\trootScope;\n\tobserver;\n\tonError;\n\tconstructor(e) {\n\t\tthis.observer = e?.observer, this.onError = e?.onError ?? ((e) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}), this.rootScope = new d(this, \"runtime\"), this.activeScope = this.rootScope;\n\t}\n\tsignal = (e, t) => new l(this, e, t);\n\tcomputed = (e, t) => {\n\t\tlet n = new u(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n;\n\t};\n\teffect = (e, t) => {\n\t\tlet n = new f(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;\n\t};\n\tcreateScope = (e) => {\n\t\tlet t = new d(this, e);\n\t\treturn this.activeScope.owned.add(t), t;\n\t};\n\tbatch = (e) => this.propagate(e);\n\tuntrack = (e) => this.withObserver(void 0, e);\n\tdispose() {\n\t\tthis.rootScope.dispose();\n\t}\n\ttrack(e) {\n\t\tlet t = this.activeObserver;\n\t\tt?.collecting !== void 0 && t.collecting.add(e);\n\t}\n\tclearDependencies(e) {\n\t\tfor (let t of e.dependencies) t.dependents.delete(e);\n\t\te.dependencies.clear();\n\t}\n\tcollect(e, t) {\n\t\treturn this.collectWith(e, t, !1);\n\t}\n\tcollectEffect(e, t) {\n\t\treturn this.collectWith(e, t, !0);\n\t}\n\twithEffectScope(e, t) {\n\t\tlet n = this.activeEffectScope;\n\t\tthis.activeEffectScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n;\n\t\t}\n\t}\n\twithObserver(e, t) {\n\t\tlet n = this.activeObserver;\n\t\tthis.activeObserver = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeObserver = n;\n\t\t}\n\t}\n\twithScope(e, t) {\n\t\tlet n = this.activeEffectScope, r = this.activeScope;\n\t\tthis.activeEffectScope = void 0, this.activeScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n, this.activeScope = r;\n\t\t}\n\t}\n\tenqueue(e) {\n\t\tthis.pending.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tenqueueListener(e) {\n\t\tthis.listeners.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tpropagate(e) {\n\t\tthis.flushDepth++;\n\t\ttry {\n\t\t\treturn e();\n\t\t} finally {\n\t\t\tthis.flushDepth--, this.flushDepth === 0 && this.flush();\n\t\t}\n\t}\n\temit(e) {\n\t\ttry {\n\t\t\tthis.observer?.(e);\n\t\t} catch (t) {\n\t\t\tthis.report(t, {\n\t\t\t\tkind: \"observer\",\n\t\t\t\tname: e.name\n\t\t\t});\n\t\t}\n\t}\n\treport(e, t) {\n\t\ttry {\n\t\t\tthis.onError(e, t);\n\t\t} catch (e) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}\n\t}\n\tcollectWith(e, t, n) {\n\t\tlet r = this.activeObserver, i = /* @__PURE__ */ new Set();\n\t\te.collecting = i, this.activeObserver = e;\n\t\ttry {\n\t\t\tlet n = t();\n\t\t\treturn this.commitDependencies(e, i), n;\n\t\t} catch (t) {\n\t\t\tthrow n && this.commitDependencies(e, i), t;\n\t\t} finally {\n\t\t\te.collecting = void 0, this.activeObserver = r;\n\t\t}\n\t}\n\tcommitDependencies(e, t) {\n\t\tfor (let n of e.dependencies) t.has(n) || n.dependents.delete(e);\n\t\tfor (let n of t) e.dependencies.has(n) || n.dependents.add(e);\n\t\te.dependencies.clear();\n\t\tfor (let n of t) e.dependencies.add(n);\n\t}\n\tflush() {\n\t\tif (this.flushing) return;\n\t\tthis.flushing = !0;\n\t\tlet e = 0;\n\t\ttry {\n\t\t\tfor (; this.pending.size > 0 || this.listeners.size > 0;) {\n\t\t\t\tif (++e > o) throw new n(`infinite reactive flush (>${o} iterations)`);\n\t\t\t\tlet t = [...this.pending], r = [...this.listeners];\n\t\t\t\tthis.pending.clear(), this.listeners.clear();\n\t\t\t\tfor (let e of t) e.run();\n\t\t\t\tfor (let e of r) try {\n\t\t\t\t\te();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.report(e, { kind: \"listener\" });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.flushing = !1;\n\t\t}\n\t}\n}, m = (e) => typeof e == \"object\" && !!e && r in e;\n//#endregion\nexport { p as ReactiveRuntime, m as isReactive };\n\n//# sourceMappingURL=runtime.js.map","//#region src/_async.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = e.signal({ status: \"pending\" }, { name: r?.name }), a = e.signal(0), o = new AbortController(), s, c = !1, l = () => {\n\t\ta.value, s?.abort();\n\t\tlet e = i.peek(), r = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, o;\n\t\ttry {\n\t\t\to = t();\n\t\t} catch (e) {\n\t\t\ti.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tlet l = new AbortController();\n\t\ts = l, i.value = r === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: r,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(n(o, { signal: l.signal }));\n\t\t} catch (e) {\n\t\t\tu = Promise.reject(e);\n\t\t}\n\t\tu.then((e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = {\n\t\t\t\tstatus: \"success\",\n\t\t\t\tvalue: e\n\t\t\t});\n\t\t}, (e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = e.effect(() => (l(), () => s?.abort()), { name: r?.name });\n\treturn u.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0, o.abort();\n\t}, { once: !0 }), {\n\t\tget disposalSignal() {\n\t\t\treturn o.signal;\n\t\t},\n\t\tdispose: () => u.dispose(),\n\t\tget disposed() {\n\t\t\treturn c;\n\t\t},\n\t\tget name() {\n\t\t\treturn i.name;\n\t\t},\n\t\tpeek: () => i.peek(),\n\t\treload: () => {\n\t\t\tc || (a.value = a.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => i.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn i.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createResource };\n\n//# sourceMappingURL=_async.js.map","//#region src/_store.ts\nvar e = (e) => (t, n) => {\n\tlet r = e.signal(t, { name: n?.name });\n\treturn {\n\t\tget name() {\n\t\t\treturn r.name;\n\t\t},\n\t\tpeek: () => r.peek(),\n\t\tset: (e) => {\n\t\t\tr.value = e;\n\t\t},\n\t\tsubscribe: (e) => r.subscribe(e),\n\t\tupdate: (e) => {\n\t\t\tr.value = e(r.peek());\n\t\t},\n\t\tget value() {\n\t\t\treturn r.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createStore };\n\n//# sourceMappingURL=_store.js.map","//#region src/_watch.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = typeof t == \"function\" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s, c = !1, l = e.effect(() => {\n\t\tlet e = i();\n\t\tif (o) {\n\t\t\to = !1, s = e, r?.immediate && n(e, void 0), c = r?.once === !0 && r.immediate === !0;\n\t\t\treturn;\n\t\t}\n\t\tif (a(s, e)) return;\n\t\tlet t = s;\n\t\ts = e, n(e, t), r?.once && l.dispose();\n\t}, { name: r?.name });\n\treturn c && l.dispose(), l;\n};\n//#endregion\nexport { e as createWatch };\n\n//# sourceMappingURL=_watch.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleError as n, RippleInfiniteLoopError as r } from \"./errors.js\";\nimport { ReactiveRuntime as i, isReactive as a } from \"./runtime.js\";\nimport { createResource as o } from \"./_async.js\";\nimport { createStore as s } from \"./_store.js\";\nimport { createWatch as c } from \"./_watch.js\";\n//#region src/index.ts\nvar l = (e) => {\n\tlet t = new i(e), n = o(t), r = s(t);\n\treturn {\n\t\tbatch: t.batch,\n\t\tcomputed: t.computed,\n\t\tcreateScope: t.createScope,\n\t\tcreateStore: r,\n\t\tdispose: () => t.dispose(),\n\t\teffect: t.effect,\n\t\tresource: n,\n\t\tsignal: t.signal,\n\t\tuntrack: t.untrack,\n\t\twatch: c(t)\n\t};\n}, u = l(), d = u.signal, f = u.computed, p = u.effect, m = u.batch, h = u.createScope, g = u.createStore, _ = u.resource, v = u.untrack, y = u.watch;\n//#endregion\nexport { e as RippleComputedCycleError, t as RippleDisposedScopeError, n as RippleError, r as RippleInfiniteLoopError, m as batch, f as computed, l as createRipple, h as createScope, g as createStore, p as effect, a as isReactive, _ as resource, d as signal, v as untrack, y as watch };\n\n//# sourceMappingURL=index.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"AAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,K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,QAAQ,CAAM,CAC5B,OAAS,EAAK,CACZ,MAAM,IAAI,EAAqB,EAAU,CAAG,EAAG,CAAE,MAAO,CAAI,CAAC,CAC/D,CAEI,IAEJ,EAAU,MAAQ,EAAM,MAAM,EAAG,EAAE,EACnC,EAAU,MAAQ,CAAC,GAAG,EAAU,MAAO,CAAK,EAC9C,CAAC,CACH,CAEA,SAAS,GAAuB,CAC9B,OAAO,EAAQ,QAAS,SAAY,CAC9B,IAEJ,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EACrB,CAAC,CACH,CAEA,SAAS,GAAgB,CACvB,EAAa,GACb,EAAG,MAAM,EAET,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,CACrB,CAEA,MAAO,CACL,UACA,UAEA,QAEA,IAAI,gBAA8B,CAChC,OAAO,EAAG,MACZ,EACA,UACA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAyB,EAAgD,CAC1E,OAAO,EAAQ,SAAY,EAAM,EAAwB,CAAO,EAAG,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC1G,EAEA,cACA,kBACA,eACA,eAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,EAEA,CAAC,OAAO,UAAiB,CACvB,EAAQ,CACV,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,CACF,CACF"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Computed } from '@vielzeug/ripple';
1
+ import type { Readable } from '@vielzeug/ripple';
2
2
  export interface Command<TData = unknown> {
3
3
  data?: TData;
4
4
  execute: (signal?: AbortSignal) => Promise<void> | void;
@@ -19,12 +19,12 @@ export interface LedgerOptions<TData = unknown> {
19
19
  onRollbackError?: (err: unknown, meta: CommandMeta<TData>) => void;
20
20
  }
21
21
  export interface Ledger<TData = unknown> {
22
- readonly canRedo: Computed<boolean>;
23
- readonly canUndo: Computed<boolean>;
24
- readonly historySize: Computed<number>;
25
- readonly historySnapshot: Computed<readonly CommandMeta<TData>[]>;
26
- readonly isProcessing: Computed<boolean>;
27
- readonly pendingCount: Computed<number>;
22
+ readonly canRedo: Readable<boolean>;
23
+ readonly canUndo: Readable<boolean>;
24
+ readonly historySize: Readable<number>;
25
+ readonly historySnapshot: Readable<readonly CommandMeta<TData>[]>;
26
+ readonly isProcessing: Readable<boolean>;
27
+ readonly pendingCount: Readable<number>;
28
28
  clear(): Promise<void>;
29
29
  readonly disposalSignal: AbortSignal;
30
30
  dispose(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/ledger",
3
- "version": "1.1.5",
3
+ "version": "2.0.0",
4
4
  "description": "Async undo/redo command history with Ripple signals for reactive canUndo/canRedo state",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,12 +34,12 @@
34
34
  "node": ">=22"
35
35
  },
36
36
  "dependencies": {
37
- "@vielzeug/ripple": "1.2.3"
37
+ "@vielzeug/ripple": "2.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/node": "^26.1.0",
40
+ "@types/node": "^26.1.2",
41
41
  "typescript": "^6.0.3",
42
- "vite": "^8.1.3",
42
+ "vite": "^8.2.0",
43
43
  "vitest": "^4.1.10"
44
44
  }
45
45
  }