text: var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
      if (kind === "m") throw new TypeError("Private method is not writable");
      if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
      if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
      return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
  };
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
      if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
      if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
      return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
  };
  var _Patcher_instances, _Patcher_id, _Patcher_patched, _Patcher_patch;
  import getOriginal from "./getOriginal";
  import PatchChain from "./patchChain";
  import removePatch from "./removePatch";
  export default class Patcher {
      constructor(embeddedName = "simian") {
          _Patcher_instances.add(this);
          _Patcher_id.set(this, void 0); // unique globally among every single object in the JS runtime
          _Patcher_patched.set(this, void 0); // to cleanup all patches with
          __classPrivateFieldSet(this, _Patcher_id, Symbol(embeddedName), "f");
          __classPrivateFieldSet(this, _Patcher_patched, new Set(), "f");
          // partial application moment
          // see, the functional programming people
          // do know how to have good clean code!
          this.after = __classPrivateFieldGet(this, _Patcher_instances, "m", _Patcher_patch).call(this, "AFTER");
          this.before = __classPrivateFieldGet(this, _Patcher_instances, "m", _Patcher_patch).call(this, "BEFORE");
          this.instead = __classPrivateFieldGet(this, _Patcher_instances, "m", _Patcher_patch).call(this, "INSTEAD");
      }
      cleanupAll() {
          for (const obj of __classPrivateFieldGet(this, _Patcher_patched, "f")) {
              for (const funcName in obj[__classPrivateFieldGet(this, _Patcher_id, "f")]) {
                  const orig = getOriginal(__classPrivateFieldGet(this, _Patcher_id, "f"), obj, funcName);
                  obj[funcName] = orig;
                  obj[__classPrivateFieldGet(this, _Patcher_id, "f")][funcName] = undefined;
              }
              obj[__classPrivateFieldGet(this, _Patcher_id, "f")] = undefined;
              delete obj[__classPrivateFieldGet(this, _Patcher_id, "f")];
          }
          __classPrivateFieldGet(this, _Patcher_patched, "f").clear();
      }
  }
  _Patcher_id = new WeakMap(), _Patcher_patched = new WeakMap(), _Patcher_instances = new WeakSet(), _Patcher_patch = function _Patcher_patch(t) {
      return (funcName, obj, patch) => {
          const orig = obj[funcName];
          if (typeof orig !== "function")
              throw new Error(`${funcName} is not a function on ${obj}`);
          // prepare to patch
          const id = Symbol();
          if (obj[__classPrivateFieldGet(this, _Patcher_id, "f")] === undefined)
              obj[__classPrivateFieldGet(this, _Patcher_id, "f")] = {};
          // create patch func
          let patchFunction;
          switch (t) {
              case "AFTER":
                  patchFunction = (ctx, func, args) => {
                      let ret = func.apply(ctx, args);
                      const newRet = patch.apply(ctx, [args, ret]);
                      if (typeof newRet !== "undefined")
                          ret = newRet;
                      return ret;
                  };
                  break;
              case "BEFORE":
                  patchFunction = (ctx, func, args) => {
                      var _a;
                      let finalArgs = args;
                      const newArgs = (_a = patch.apply(ctx, [args])) !== null && _a !== void 0 ? _a : args;
                      if (Array.isArray(newArgs))
                          finalArgs = newArgs;
                      return func.apply(ctx, finalArgs);
                  };
                  break;
              case "INSTEAD":
                  patchFunction = (ctx, func, args) => patch.apply(ctx, [args, func.bind(ctx)]);
                  break;
              default:
                  break;
          }
          // add to patch chain
          let patchChain = obj[__classPrivateFieldGet(this, _Patcher_id, "f")][funcName];
          if (patchChain === undefined)
              patchChain = new PatchChain(id, orig, patchFunction);
          else
              patchChain = new PatchChain(id, patchChain, patchFunction);
          obj[__classPrivateFieldGet(this, _Patcher_id, "f")][funcName] = patchChain;
          // inject patch!
          //obj[funcName] = patchChain.data.func;
          obj[funcName] = function () {
              return patchChain.data.func(this, ...arguments);
          };
          // i read thru Cumcord patcher src to find this one lol
          // attach original function props to patched function
          Object.assign(obj[funcName], orig);
          __classPrivateFieldGet(this, _Patcher_patched, "f").add(obj);
          return () => removePatch(obj, funcName, id, __classPrivateFieldGet(this, _Patcher_id, "f"));
      };
  };
  