var M = Object.defineProperty;
var t = (r, e) => M(r, "name", { value: e, configurable: !0 });
function h() {
  return h = Object.assign ? Object.assign.bind() : function(r) {
    for (var e = 1; e < arguments.length; e++) {
      var i = arguments[e];
      for (var n in i)
        Object.prototype.hasOwnProperty.call(i, n) && (r[n] = i[n]);
    }
    return r;
  }, h.apply(this, arguments);
}
t(h, "_extends");
var D = !1;
try {
  D = typeof localStorage < "u";
} catch {
}
var j = typeof process < "u", H = D && /* @__PURE__ */ localStorage.getItem("DEBUG") || j && process.env.DEBUG, C = H ? console.log : function(r) {
  return "";
};
function O(r, e, i, n, b) {
  n === void 0 && (n = {});
  var o = h({}, L(i), n), u = T(r, e, o, i, b), a = u.languageServiceHost, c = u.updateFile, m = u.deleteFile, f = i.createLanguageService(a), g = f.getCompilerOptionsDiagnostics();
  if (g.length) {
    var v = E(r, n, i);
    throw new Error(i.formatDiagnostics(g, v.compilerHost));
  }
  return {
    // @ts-ignore
    name: "vfs",
    sys: r,
    languageService: f,
    getSourceFile: /* @__PURE__ */ t(function(l) {
      var s;
      return (s = f.getProgram()) == null ? void 0 : s.getSourceFile(l);
    }, "getSourceFile"),
    createFile: /* @__PURE__ */ t(function(l, s) {
      c(i.createSourceFile(l, s, o.target, !1));
    }, "createFile"),
    updateFile: /* @__PURE__ */ t(function(l, s, d) {
      var w = f.getProgram().getSourceFile(l);
      if (!w)
        throw new Error("Did not find a source file for " + l);
      var y = w.text, F = d ?? i.createTextSpan(0, y.length), P = y.slice(0, F.start) + s + y.slice(F.start + F.length), k = i.updateSourceFile(w, P, {
        span: F,
        newLength: s.length
      });
      c(k);
    }, "updateFile"),
    deleteFile: /* @__PURE__ */ t(function(l) {
      var s = f.getProgram().getSourceFile(l);
      s && m(s);
    }, "deleteFile")
  };
}
t(O, "createVirtualTypeScriptEnvironment");
var V = /* @__PURE__ */ t(function(e, i) {
  var n = e.target || i.ScriptTarget.ES5, b = e.lib || [], o = ["lib.d.ts", "lib.core.d.ts", "lib.decorators.d.ts", "lib.decorators.legacy.d.ts", "lib.dom.asynciterable.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts", "lib.webworker.asynciterable.d.ts", "lib.webworker.d.ts", "lib.webworker.importscripts.d.ts", "lib.webworker.iterable.d.ts", "lib.scripthost.d.ts", "lib.es5.d.ts", "lib.es6.d.ts", "lib.es7.d.ts", "lib.core.es6.d.ts", "lib.core.es7.d.ts", "lib.es2015.collection.d.ts", "lib.es2015.core.d.ts", "lib.es2015.d.ts", "lib.es2015.generator.d.ts", "lib.es2015.iterable.d.ts", "lib.es2015.promise.d.ts", "lib.es2015.proxy.d.ts", "lib.es2015.reflect.d.ts", "lib.es2015.symbol.d.ts", "lib.es2015.symbol.wellknown.d.ts", "lib.es2016.array.include.d.ts", "lib.es2016.d.ts", "lib.es2016.full.d.ts", "lib.es2016.intl.d.ts", "lib.es2017.arraybuffer.d.ts", "lib.es2017.d.ts", "lib.es2017.date.d.ts", "lib.es2017.full.d.ts", "lib.es2017.intl.d.ts", "lib.es2017.object.d.ts", "lib.es2017.sharedmemory.d.ts", "lib.es2017.string.d.ts", "lib.es2017.typedarrays.d.ts", "lib.es2018.asyncgenerator.d.ts", "lib.es2018.asynciterable.d.ts", "lib.es2018.d.ts", "lib.es2018.full.d.ts", "lib.es2018.intl.d.ts", "lib.es2018.promise.d.ts", "lib.es2018.regexp.d.ts", "lib.es2019.array.d.ts", "lib.es2019.d.ts", "lib.es2019.full.d.ts", "lib.es2019.intl.d.ts", "lib.es2019.object.d.ts", "lib.es2019.string.d.ts", "lib.es2019.symbol.d.ts", "lib.es2020.bigint.d.ts", "lib.es2020.d.ts", "lib.es2020.date.d.ts", "lib.es2020.full.d.ts", "lib.es2020.intl.d.ts", "lib.es2020.number.d.ts", "lib.es2020.promise.d.ts", "lib.es2020.sharedmemory.d.ts", "lib.es2020.string.d.ts", "lib.es2020.symbol.wellknown.d.ts", "lib.es2021.d.ts", "lib.es2021.full.d.ts", "lib.es2021.intl.d.ts", "lib.es2021.promise.d.ts", "lib.es2021.string.d.ts", "lib.es2021.weakref.d.ts", "lib.es2022.array.d.ts", "lib.es2022.d.ts", "lib.es2022.error.d.ts", "lib.es2022.full.d.ts", "lib.es2022.intl.d.ts", "lib.es2022.object.d.ts", "lib.es2022.regexp.d.ts", "lib.es2022.sharedmemory.d.ts", "lib.es2022.string.d.ts", "lib.es2023.array.d.ts", "lib.es2023.collection.d.ts", "lib.es2023.d.ts", "lib.es2023.full.d.ts", "lib.es2023.intl.d.ts", "lib.es2024.arraybuffer.d.ts", "lib.es2024.collection.d.ts", "lib.es2024.d.ts", "lib.es2024.full.d.ts", "lib.es2024.object.d.ts", "lib.es2024.promise.d.ts", "lib.es2024.regexp.d.ts", "lib.es2024.sharedmemory.d.ts", "lib.es2024.string.d.ts", "lib.esnext.array.d.ts", "lib.esnext.asynciterable.d.ts", "lib.esnext.bigint.d.ts", "lib.esnext.collection.d.ts", "lib.esnext.d.ts", "lib.esnext.decorators.d.ts", "lib.esnext.disposable.d.ts", "lib.esnext.float16.d.ts", "lib.esnext.full.d.ts", "lib.esnext.intl.d.ts", "lib.esnext.iterator.d.ts", "lib.esnext.object.d.ts", "lib.esnext.promise.d.ts", "lib.esnext.regexp.d.ts", "lib.esnext.string.d.ts", "lib.esnext.symbol.d.ts", "lib.esnext.weakref.d.ts"], u = i.ScriptTarget[n], a = o.filter(function(p) {
    return p.startsWith("lib." + u.toLowerCase());
  }), c = o.indexOf(a.pop()), m = /* @__PURE__ */ t(function(l) {
    return l && l.length ? l.reduce(function(s, d) {
      return d > s ? d : s;
    }) : void 0;
  }, "getMax"), f = b.map(function(p) {
    var l = o.filter(function(d) {
      return d.startsWith("lib." + p.toLowerCase());
    });
    if (l.length === 0) return 0;
    var s = o.indexOf(l.pop());
    return s;
  }), g = m(f) || 0, v = Math.max(c, g);
  return o.slice(0, v + 1);
}, "knownLibFilesForCompilerOptions"), _ = /* @__PURE__ */ t(function(e, i, n, b, o, u, a) {
  var c = fetch, m = /* @__PURE__ */ new Map(), f = V(e, b), g = "https://playgroundcdn.typescriptlang.org/cdn/" + i + "/typescript/lib/";
  function v() {
    return Promise.all(f.map(function(l) {
      return c(g + l).then(function(s) {
        return s.text();
      });
    })).then(function(l) {
      l.forEach(function(s, d) {
        return m.set("/" + f[d], s);
      });
    }).catch(function() {
    });
  }
  t(v, "uncached");
  var p = v;
  return p().then(function() {
    return m;
  });
}, "createDefaultMapFromCDN");
function x(r) {
  throw new Error("Method '" + r + "' is not implemented.");
}
t(x, "notImplemented");
function S(r, e) {
  return function() {
    for (var i = arguments.length, n = new Array(i), b = 0; b < i; b++)
      n[b] = arguments[b];
    var o = e.apply(void 0, n), u = typeof o == "string" ? o.slice(0, 80) + "..." : o;
    return C.apply(void 0, ["> " + r].concat(n)), C("< " + u), o;
  };
}
t(S, "audit");
var L = /* @__PURE__ */ t(function(e) {
  return h({}, e.getDefaultCompilerOptions(), {
    jsx: e.JsxEmit.React,
    strict: !0,
    esModuleInterop: !0,
    module: e.ModuleKind.ESNext,
    suppressOutputPathCheck: !0,
    skipLibCheck: !0,
    skipDefaultLibCheck: !0,
    moduleResolution: e.ModuleResolutionKind.NodeJs
  });
}, "defaultCompilerOptions"), N = /* @__PURE__ */ t(function(e) {
  return e.replace("/", "/lib.").toLowerCase();
}, "libize");
function z(r) {
  return {
    args: [],
    createDirectory: /* @__PURE__ */ t(function() {
      return x("createDirectory");
    }, "createDirectory"),
    // TODO: could make a real file tree
    directoryExists: S("directoryExists", function(e) {
      return Array.from(r.keys()).some(function(i) {
        return i.startsWith(e);
      });
    }),
    exit: /* @__PURE__ */ t(function() {
      return x("exit");
    }, "exit"),
    fileExists: S("fileExists", function(e) {
      return r.has(e) || r.has(N(e));
    }),
    getCurrentDirectory: /* @__PURE__ */ t(function() {
      return "/";
    }, "getCurrentDirectory"),
    getDirectories: /* @__PURE__ */ t(function() {
      return [];
    }, "getDirectories"),
    getExecutingFilePath: /* @__PURE__ */ t(function() {
      return x("getExecutingFilePath");
    }, "getExecutingFilePath"),
    readDirectory: S("readDirectory", function(e) {
      return e === "/" ? Array.from(r.keys()) : [];
    }),
    readFile: S("readFile", function(e) {
      var i;
      return (i = r.get(e)) != null ? i : r.get(N(e));
    }),
    resolvePath: /* @__PURE__ */ t(function(i) {
      return i;
    }, "resolvePath"),
    newLine: `
`,
    useCaseSensitiveFileNames: !0,
    write: /* @__PURE__ */ t(function() {
      return x("write");
    }, "write"),
    writeFile: /* @__PURE__ */ t(function(i, n) {
      r.set(i, n);
    }, "writeFile"),
    deleteFile: /* @__PURE__ */ t(function(i) {
      r.delete(i);
    }, "deleteFile")
  };
}
t(z, "createSystem");
function E(r, e, i) {
  var n = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ t(function(a) {
    return n.set(a.fileName, a), a;
  }, "save"), o = {
    compilerHost: h({}, r, {
      getCanonicalFileName: /* @__PURE__ */ t(function(a) {
        return a;
      }, "getCanonicalFileName"),
      getDefaultLibFileName: /* @__PURE__ */ t(function() {
        return "/" + i.getDefaultLibFileName(e);
      }, "getDefaultLibFileName"),
      // '/lib.d.ts',
      // getDefaultLibLocation: () => '/',
      getNewLine: /* @__PURE__ */ t(function() {
        return r.newLine;
      }, "getNewLine"),
      getSourceFile: /* @__PURE__ */ t(function(a, c) {
        var m;
        return n.get(a) || b(i.createSourceFile(a, r.readFile(a), (m = c ?? e.target) != null ? m : L(i).target, !1));
      }, "getSourceFile"),
      useCaseSensitiveFileNames: /* @__PURE__ */ t(function() {
        return r.useCaseSensitiveFileNames;
      }, "useCaseSensitiveFileNames")
    }),
    updateFile: /* @__PURE__ */ t(function(a) {
      var c = n.has(a.fileName);
      return r.writeFile(a.fileName, a.text), n.set(a.fileName, a), c;
    }, "updateFile"),
    deleteFile: /* @__PURE__ */ t(function(a) {
      var c = n.has(a.fileName);
      return n.delete(a.fileName), r.deleteFile(a.fileName), c;
    }, "deleteFile")
  };
  return o;
}
t(E, "createVirtualCompilerHost");
function T(r, e, i, n, b) {
  var o = [].concat(e), u = E(r, i, n), a = u.compilerHost, c = u.updateFile, m = u.deleteFile, f = /* @__PURE__ */ new Map(), g = 0, v = h({}, a, {
    getProjectVersion: /* @__PURE__ */ t(function() {
      return g.toString();
    }, "getProjectVersion"),
    getCompilationSettings: /* @__PURE__ */ t(function() {
      return i;
    }, "getCompilationSettings"),
    getCustomTransformers: /* @__PURE__ */ t(function() {
      return b;
    }, "getCustomTransformers"),
    // A couple weeks of 4.8 TypeScript nightlies had a bug where the Program's
    // list of files was just a reference to the array returned by this host method,
    // which means mutations by the host that ought to result in a new Program being
    // created were not detected, since the old list of files and the new list of files
    // were in fact a reference to the same underlying array. That was fixed in
    // https://github.com/microsoft/TypeScript/pull/49813, but since the twoslash runner
    // is used in bisecting for changes, it needs to guard against being busted in that
    // couple-week period, so we defensively make a slice here.
    getScriptFileNames: /* @__PURE__ */ t(function() {
      return o.slice();
    }, "getScriptFileNames"),
    getScriptSnapshot: /* @__PURE__ */ t(function(s) {
      var d = r.readFile(s);
      if (d && typeof d == "string")
        return n.ScriptSnapshot.fromString(d);
    }, "getScriptSnapshot"),
    getScriptVersion: /* @__PURE__ */ t(function(s) {
      return f.get(s) || "0";
    }, "getScriptVersion"),
    writeFile: r.writeFile
  }), p = {
    languageServiceHost: v,
    updateFile: /* @__PURE__ */ t(function(s) {
      g++, f.set(s.fileName, g.toString()), o.includes(s.fileName) || o.push(s.fileName), c(s);
    }, "updateFile"),
    deleteFile: /* @__PURE__ */ t(function(s) {
      g++, f.set(s.fileName, g.toString());
      var d = o.indexOf(s.fileName);
      d !== -1 && o.splice(d, 1), m(s);
    }, "deleteFile")
  };
  return p;
}
t(T, "createVirtualLanguageServiceHost");
export {
  _ as createDefaultMapFromCDN,
  z as createSystem,
  E as createVirtualCompilerHost,
  T as createVirtualLanguageServiceHost,
  O as createVirtualTypeScriptEnvironment,
  V as knownLibFilesForCompilerOptions
};
