{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-core/src/client/reactive/utils/stack.js"],"names":["Stack","constructor","arr","push","element","pop","length","top","withElement","el","callback","context","call","findUp","args","reverse","find","findDown"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;AAiBe,YAAMA,KAAN,CAAY;AACzB;;;;AAIAC,sBAAc;AACZ,eAAKC,GAAL,GAAW,EAAX;AACD;;AAED;;;;;AAKAC,aAAKC,OAAL,EAAc;AACZ,eAAKF,GAAL,CAASC,IAAT,CAAcC,OAAd;AACD;;AAED;;;;AAIAC,cAAM;AACJ,eAAKH,GAAL,CAASI,MAAT;AACD;;AAED;;;;;AAKAC,cAAM;AACJ;AACA;AACA,iBAAO,KAAKL,GAAL,CAAS,KAAKA,GAAL,CAASI,MAAT,GAAkB,CAA3B,CAAP;AACD;;AAED;;;;;;;;AAQAE,oBAAYC,EAAZ,EAAgBC,QAAhB,EAA0BC,OAA1B,EAAmC;AACjC,eAAKR,IAAL,CAAUM,EAAV;AACA,cAAI;AACFC,qBAASE,IAAT,CAAcD,OAAd;AACD,WAFD,SAEU;AACR,iBAAKN,GAAL;AACD;AACF;;AAED;;;;;;;AAOAQ,eAAO,GAAGC,IAAV,EAAgB;AACd,iBAAO,KAAKZ,GAAL,CAASa,OAAT,GAAmBC,IAAnB,CAAwB,GAAGF,IAA3B,CAAP;AACD;;AAED;;;;;;;AAOAG,iBAAS,GAAGH,IAAZ,EAAkB;AAChB,iBAAO,KAAKZ,GAAL,CAASc,IAAT,CAAc,GAAGF,IAAjB,CAAP;AACD;;AA1EwB;;yBAANd,K;;;;;;;;6BAAAA,sC","file":"stack.js","sourcesContent":["/**\n * @class Stack\n *\n * @example\n * import Stack from 'stack-es2015-module';\n *\n * let stack = new Stack();\n *\n * stack.push(42);\n * stack.push(17);\n * stack.top(); // 17\n * stack.pop();\n * stack.top(); // 42\n * stack.withElement(33, () => {\n *   stack.top(); // 33\n * });\n */\nexport default class Stack {\n  /**\n   * Initializes a new empty `Stack`.\n   * @method constructor\n   */\n  constructor() {\n    this.arr = [];\n  };\n\n  /**\n   * Pushes the `element` at the top of the stack.\n   * @method push\n   * @param {any} element - The element to be pushed on top of the stack.\n   */\n  push(element) {\n    this.arr.push(element);\n  }\n\n  /**\n   * Pops the top element of the stack.\n   * @method pop\n   */\n  pop() {\n    this.arr.length--;\n  }\n\n  /**\n   * Returns the top element of the stack.\n   * @method top\n   * @return {any} The value on top of the stack.\n   */\n  top() {\n    // TODO: .last() not defined in older node versions\n    // return this.arr.last();\n    return this.arr[this.arr.length - 1];\n  }\n\n  /**\n   * Pushes the `element` at the top of the stack and executes the `callback` with the optional `context`.\n   * After successfully returning from the `callback` or upon an uncatched error, the top element is poped from the stack.\n   * @method withElement\n   * @param {any} el - The element temporarily on stack.\n   * @param {function} callback - The function to be called.\n   * @param {Object} context - The this reference use for the call.\n   */\n  withElement(el, callback, context) {\n    this.push(el);\n    try {\n      callback.call(context);\n    } finally {\n      this.pop();\n    }\n  }\n\n  /**\n   * Returns an element from the stack that satisfies the given condition, search fron bottom to top.\n   * @method findUp\n   * @param {function} callback - The condition to be called.\n   * @param {any} thisArg - This object passed as `this` into the `callback`.\n   * @return {any} The element satisfying the condition.\n   */\n  findUp(...args) {\n    return this.arr.reverse().find(...args);\n  }\n\n  /**\n   * Returns an element from the stack that satisfies the given condition, search from top to bottom.\n   * @method findDown\n   * @param {function} callback - The condition to be called.\n   * @param {any} thisArg - This object passed as `this` into the `callback`.\n   * @return {any} The element satisfying the condition.\n   */\n  findDown(...args) {\n    return this.arr.find(...args);\n  }\n\n}\n"]}