export class HistoryEntry{valid(){throw new Error("not implemented")}reveal(){}}export class SimpleHistoryManager{constructor(e){this._entries=[],this._activeEntryIndex=-1,this._coalescingReadonly=0,this._historyDepth=e}readOnlyLock(){++this._coalescingReadonly}releaseReadOnlyLock(){--this._coalescingReadonly}readOnly(){return Boolean(this._coalescingReadonly)}filterOut(e){if(this.readOnly())return;const t=[];let i=0;for(let s=0;s<this._entries.length;++s)e(this._entries[s])?s<=this._activeEntryIndex&&++i:t.push(this._entries[s]);this._entries=t,this._activeEntryIndex=Math.max(0,this._activeEntryIndex-i)}empty(){return!this._entries.length}active(){return this.empty()?null:this._entries[this._activeEntryIndex]}push(e){this.readOnly()||(this.empty()||this._entries.splice(this._activeEntryIndex+1),this._entries.push(e),this._entries.length>this._historyDepth&&this._entries.shift(),this._activeEntryIndex=this._entries.length-1)}rollback(){if(this.empty())return!1;let e=this._activeEntryIndex-1;for(;e>=0&&!this._entries[e].valid();)--e;return!(e<0)&&(this.readOnlyLock(),this._entries[e].reveal(),this.releaseReadOnlyLock(),this._activeEntryIndex=e,!0)}rollover(){let e=this._activeEntryIndex+1;for(;e<this._entries.length&&!this._entries[e].valid();)++e;return!(e>=this._entries.length)&&(this.readOnlyLock(),this._entries[e].reveal(),this.releaseReadOnlyLock(),this._activeEntryIndex=e,!0)}}