{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-tom/src/client/command-history.js"],"names":["CommandHistory","constructor","clear","addCommand","command","stack","length","undoIndex","push","undo","undefined","strokes","Math","max","cmd","unexecute","redo","min","execute"],"mappings":";;;;;;;;AACe,YAAMA,cAAN,CAAqB;;AAElCC,sBAAc;AACZ,eAAKC,KAAL;AACD;;AAEDC,mBAAWC,OAAX,EAAoB;AAClB,eAAKC,KAAL,CAAWC,MAAX,GAAoB,KAAKC,SAAzB;AACA,eAAKF,KAAL,CAAWG,IAAX,CAAgBJ,OAAhB;AACA,eAAKG,SAAL,GAAiB,KAAKF,KAAL,CAAWC,MAA5B;AACD;;AAEDG,eAAO;AACL,cAAI,KAAKF,SAAL,KAAmBG,SAAvB,EAAkC;AAChC,iBAAKH,SAAL,GAAiB,KAAKI,OAAL,CAAaL,MAA9B;AACD;AACD,eAAKC,SAAL,GAAiBK,KAAKC,GAAL,CAAS,CAAT,EAAY,KAAKN,SAAL,GAAiB,CAA7B,CAAjB;AACA,cAAIO,MAAM,KAAKT,KAAL,CAAW,KAAKE,SAAhB,CAAV;AACA,cAAGO,GAAH,EAAQ;AACNA,gBAAIC,SAAJ;AACD;AACF;;AAEDC,eAAO;AACL,cAAI,KAAKT,SAAL,KAAmBG,SAAvB,EAAkC;AAChC;AACD;AACD,cAAII,MAAM,KAAKT,KAAL,CAAW,KAAKE,SAAhB,CAAV;AACA,eAAKA,SAAL,GAAiBK,KAAKK,GAAL,CAAS,KAAKZ,KAAL,CAAWC,MAApB,EAA4B,KAAKC,SAAL,GAAiB,CAA7C,CAAjB;AACA,cAAGO,GAAH,EAAQ;AACNA,gBAAII,OAAJ;AACD;AACF;;AAEDhB,gBAAQ;AACN,eAAKG,KAAL,GAAa,EAAb;AACA,eAAKE,SAAL,GAAiB,IAAjB;AACD;AArCiC;;yBAAfP,c","file":"command-history.js","sourcesContent":["\t\nexport default class CommandHistory {\n  \n  constructor() {\n    this.clear();\n  }\n  \n  addCommand(command) {\n    this.stack.length = this.undoIndex;\n    this.stack.push(command);\n    this.undoIndex = this.stack.length;\n  }\n  \n  undo() {\n    if (this.undoIndex === undefined) {\n      this.undoIndex = this.strokes.length;\n    }\n    this.undoIndex = Math.max(0, this.undoIndex - 1); \n    var cmd = this.stack[this.undoIndex];\n    if(cmd) { \n      cmd.unexecute();\n    }\n  }\n  \n  redo() {\n    if (this.undoIndex === undefined) {\n      return;\n    }\n    var cmd = this.stack[this.undoIndex];\n    this.undoIndex = Math.min(this.stack.length, this.undoIndex + 1); \n    if(cmd) { \n      cmd.execute();\n    }\n  }\n  \n  clear() {\n    this.stack = [];\n    this.undoIndex = null;\n  }\n}"]}