import { s as __toESM } from "./chunk-BNovOVIE.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { it as parseHtmlContent, rt as ansiToPlainText } from "./html-to-image-CpggM7u1.js";
import { u as createLucideIcon } from "./dist-D3ZI9nhS.js";
import { t as Strings } from "./strings-BiIhGaI8.js";
import { t as require_jsx_runtime } from "./jsx-runtime-COBk7ree.js";
import { n as mapWithConcurrency } from "./semaphore-CNDGTzkX.js";
var File = createLucideIcon("file", [["path", {
  d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
  key: "1oefj6"
}], ["path", {
  d: "M14 2v5a1 1 0 0 0 1 1h5",
  key: "wfsgrz"
}]]);
function deserializeBlob(e) {
  var _a;
  let [_, v] = e.split(",", 2), y = (_a = /^data:(.+);base64$/.exec(_)) == null ? void 0 : _a[1], b = atob(v), x = b.length, S = new Uint8Array(x);
  for (let e2 = 0; e2 < x; e2++) S[e2] = b.charCodeAt(e2);
  return new Blob([S], { type: y });
}
function defineCustomEvent(e) {
  return () => ({
    TYPE: e,
    is(_) {
      return _.type === e;
    },
    create(_) {
      return new CustomEvent(e, _);
    }
  });
}
const MarimoValueInputEvent = defineCustomEvent("marimo-value-input")(), MarimoValueUpdateEvent = defineCustomEvent("marimo-value-update")(), MarimoValueReadyEvent = defineCustomEvent("marimo-value-ready")(), MarimoIncomingMessageEvent = defineCustomEvent("marimo-incoming-message")();
function createInputEvent(e, _) {
  return MarimoValueInputEvent.create({
    bubbles: true,
    composed: true,
    detail: {
      value: e,
      element: _
    }
  });
}
var import_compiler_runtime = require_compiler_runtime(), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
const PythonIcon = (e) => {
  let _ = (0, import_compiler_runtime.c)(4), v, y;
  _[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (v = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", { children: "Python Logo" }), y = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z" }), _[0] = v, _[1] = y) : (v = _[0], y = _[1]);
  let b;
  return _[2] === e ? b = _[3] : (b = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
    xmlns: "http://www.w3.org/2000/svg",
    width: "1em",
    height: "1em",
    fill: "currentColor",
    viewBox: "0 0 448 512",
    ...e,
    children: [v, y]
  }), _[2] = e, _[3] = b), b;
};
var FILE_READ_CONCURRENCY = 5;
function blobToString(e, _) {
  return new Promise((v) => {
    let y = new FileReader();
    y.readAsDataURL(e), y.onload = (e2) => {
      var _a;
      if ((_a = e2.target) == null ? void 0 : _a.result) {
        let y2 = e2.target.result;
        v(_ === "base64" ? y2.slice(y2.indexOf(",") + 1) : y2);
      }
    };
  });
}
function filesToBase64(e) {
  return mapWithConcurrency(e, FILE_READ_CONCURRENCY, async (e2) => {
    let _ = await blobToString(e2, "base64");
    return [e2.name, _];
  });
}
function processOutput(e) {
  return e.mimetype.startsWith("application/vnd.marimo") || e.mimetype === "text/html" ? parseHtmlContent(Strings.asString(e.data)) : ansiToPlainText(Strings.asString(e.data));
}
export {
  MarimoIncomingMessageEvent as a,
  MarimoValueUpdateEvent as c,
  File as d,
  PythonIcon as i,
  createInputEvent as l,
  blobToString as n,
  MarimoValueInputEvent as o,
  filesToBase64 as r,
  MarimoValueReadyEvent as s,
  processOutput as t,
  deserializeBlob as u
};
