{"version":3,"file":"historyNavigator.mjs","sources":["../../../src/common/historyNavigator/historyNavigator.ts"],"sourcesContent":["class HistoryNavigator {\n  history: (string | number)[];\n  currIndex: number;\n  historyLimit: number | undefined;\n\n  constructor(history?: (string | number)[], historyLimit?: number) {\n    this.history = history && history.length > 0 ? history : [''];\n    this.currIndex = this.history.length - 1;\n    this.historyLimit = historyLimit;\n  }\n\n  reset = (newHistory?: (string | number)[], historyLimit = 20) => {\n    this.history = newHistory && newHistory.length > 0 ? newHistory : [''];\n    this.currIndex = this.history.length - 1;\n    this.historyLimit = historyLimit;\n  };\n\n  add = (element: string | number) => {\n    if (!this.historyLimit || this.history.length <= this.historyLimit) {\n      this.history.push(element);\n      // Always keep the current Index to the latest change\n      this.currIndex = this.history.length - 1;\n    } else {\n      // @TODO not needed now but maybe it can be useful to implement a limit.\n      this.currIndex = this.history.length - 1;\n    }\n  };\n\n  redo = () => {\n    const historyLength = this.history.length;\n    this.currIndex = this.currIndex + 1 < historyLength ? this.currIndex + 1 : historyLength - 1;\n    return this.history[this.currIndex];\n  };\n\n  undo = () => {\n    this.currIndex = this.currIndex - 1 > 0 ? this.currIndex - 1 : 0;\n    return this.history[this.currIndex];\n  };\n}\n\nexport default HistoryNavigator;\n"],"names":["HistoryNavigator","history","currIndex","historyLimit","constructor","length","reset","newHistory","add","element","push","redo","historyLength","undo"],"mappings":"AAAA,MAAMA,gBAAgB,CAAA;EACpBC,OAAO;EACPC,SAAS;EACTC,YAAY;AAEZC,EAAAA,WAAAA,CAAYH,OAA6B,EAAEE,YAAqB,EAAA;AAC9D,IAAA,IAAI,CAACF,OAAO,GAAGA,OAAO,IAAIA,OAAO,CAACI,MAAM,GAAG,CAAC,GAAGJ,OAAO,GAAG,CAAC,EAAE,CAAC;IAC7D,IAAI,CAACC,SAAS,GAAG,IAAI,CAACD,OAAO,CAACI,MAAM,GAAG,CAAC;IACxC,IAAI,CAACF,YAAY,GAAGA,YAAY;AAClC,EAAA;AAEAG,EAAAA,KAAK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