import { getNextElement as f, getNextMarker as b, insert as g, createComponent as c, effect as oe, setAttribute as ve, runHydrationEvents as ce, delegateEvents as $e, template as m, use as _e, memo as en, spread as nn, mergeProps as tn, hydrate as on, render as rn } from "solid-js/web";
import { createSignal as B, onMount as we, onCleanup as an, For as ln, Show as x, createEffect as sn, createContext as cn, useContext as dn } from "solid-js";
import { Compartment as Ce, SelectionRange as un, EditorSelection as fn, RangeSetBuilder as Le, Transaction as mn, EditorState as gn } from "@codemirror/state";
import { markdown as pn, markdownLanguage as hn } from "@codemirror/lang-markdown";
import { languages as kn } from "@codemirror/language-data";
import { EditorView as P, Decoration as S, ViewPlugin as Se, keymap as bn } from "@codemirror/view";
import { syntaxTree as de, syntaxHighlighting as xn, HighlightStyle as vn } from "@codemirror/language";
import { defaultKeymap as yn, historyKeymap as $n, indentMore as _n, indentLess as wn, history as Cn } from "@codemirror/commands";
import { tags as d } from "@lezer/highlight";
const Ln = "data-ink-mde-ssr-hydration-marker", Sn = `[${Ln}]`, Mn = () => ({}), z = {
  array: "[object Array]",
  object: "[object Object]",
  string: "[object String]",
  undefined: "[object Undefined]",
  window: "[object Window]"
}, Dn = (e) => {
  if (Object.prototype.toString.call(e) === z.object)
    return `[object ${e.constructor.name}]`;
}, T = (e, n) => Dn(e) === n, Hn = (e, n) => {
  const t = /* @__PURE__ */ new WeakMap(), o = (r, i) => t.get(r) || (T(r, z.object) && t.set(r, !0), T(i, z.undefined)) ? r : T(r, z.array) && T(i, z.array) ? [...i] : T(r, z.object) && T(i, z.object) ? Object.keys(r).reduce((l, a) => (Object.hasOwnProperty.call(i, a) ? l[a] = o(r[a], i[a]) : l[a] = r[a], l), {}) : i;
  return o(e, n);
}, W = (e, n) => Hn(e, n);
var V = /* @__PURE__ */ ((e) => (e.Auto = "auto", e.Dark = "dark", e.Light = "light", e))(V || {}), An = /* @__PURE__ */ ((e) => (e.Appearance = "appearance", e.Attribution = "attribution", e.Autocomplete = "autocomplete", e.Images = "images", e.ReadOnly = "readonly", e.Spellcheck = "spellcheck", e.Vim = "vim", e))(An || {}), h = /* @__PURE__ */ ((e) => (e.Bold = "bold", e.Code = "code", e.CodeBlock = "code_block", e.Heading = "heading", e.Image = "image", e.Italic = "italic", e.Link = "link", e.List = "list", e.OrderedList = "ordered_list", e.Quote = "quote", e.TaskList = "task_list", e))(h || {}), re = /* @__PURE__ */ ((e) => (e.Completion = "completion", e.Default = "default", e.Grammar = "grammar", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.End = "end", e.Start = "start", e))(ie || {});
const ye = () => document.createElement("div"), Me = () => window.matchMedia("(prefers-color-scheme: dark)").matches, zn = (e) => e === V.Dark ? !0 : e === V.Light ? !1 : Me(), te = (e) => {
  const n = [
    // --ink-*
    { suffix: "border-radius", default: "0.25rem" },
    { suffix: "color", default: "currentColor" },
    { suffix: "flex-direction", default: "column" },
    { suffix: "font-family", default: "inherit" },
    // --ink-block-*
    { suffix: "block-background-color", default: "#121212", light: "#f5f5f5" },
    { suffix: "block-background-color-on-hover", default: "#0f0f0f", light: "#e0e0e0" },
    { suffix: "block-max-height", default: "20rem" },
    { suffix: "block-padding", default: "0.5rem" },
    // --ink-code-*
    { suffix: "code-background-color", default: "var(--ink-internal-block-background-color)" },
    { suffix: "code-color", default: "inherit" },
    { suffix: "code-font-family", default: "'Monaco', Courier, monospace" },
    // --ink-editor-*
    { suffix: "editor-font-size", default: "1em" },
    { suffix: "editor-line-height", default: "2em" },
    { suffix: "editor-padding", default: "0.5rem" },
    { suffix: "inline-padding", default: "0.125rem" },
    // --ink-modal-*
    { suffix: "modal-position", default: "fixed" },
    // --ink-syntax-*
    { suffix: "syntax-atom-color", default: "#d19a66" },
    { suffix: "syntax-comment-color", default: "#abb2bf" },
    { suffix: "syntax-comment-font-style", default: "italic" },
    { suffix: "syntax-emphasis-color", default: "inherit" },
    { suffix: "syntax-emphasis-font-style", default: "italic" },
    { suffix: "syntax-hashtag-background-color", default: "#222", light: "#eee" },
    { suffix: "syntax-hashtag-color", default: "inherit" },
    { suffix: "syntax-heading-color", default: "inherit" },
    { suffix: "syntax-heading-font-weight", default: "600" },
    { suffix: "syntax-heading1-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading1-font-size", default: "1.6em" },
    { suffix: "syntax-heading1-font-weight", default: "600" },
    { suffix: "syntax-heading2-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading2-font-size", default: "1.5em" },
    { suffix: "syntax-heading2-font-weight", default: "600" },
    { suffix: "syntax-heading3-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading3-font-size", default: "1.4em" },
    { suffix: "syntax-heading3-font-weight", default: "600" },
    { suffix: "syntax-heading4-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading4-font-size", default: "1.3em" },
    { suffix: "syntax-heading4-font-weight", default: "600" },
    { suffix: "syntax-heading5-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading5-font-size", default: "1.2em" },
    { suffix: "syntax-heading5-font-weight", default: "600" },
    { suffix: "syntax-heading6-color", default: "var(--ink-internal-syntax-heading-color, inherit)" },
    { suffix: "syntax-heading6-font-size", default: "1.1em" },
    { suffix: "syntax-heading6-font-weight", default: "600" },
    { suffix: "syntax-highlight-background-color", default: "#555555" },
    { suffix: "syntax-keyword-color", default: "#c678dd" },
    { suffix: "syntax-link-color", default: "inherit" },
    { suffix: "syntax-meta-color", default: "#abb2bf" },
    { suffix: "syntax-monospace-color", default: "var(--ink-internal-code-color)" },
    { suffix: "syntax-monospace-font-family", default: "var(--ink-internal-code-font-family)" },
    { suffix: "syntax-name-color", default: "#d19a66" },
    { suffix: "syntax-name-label-color", default: "#abb2bf" },
    { suffix: "syntax-name-property-color", default: "#96c0d8" },
    { suffix: "syntax-name-property-definition-color", default: "#e06c75" },
    { suffix: "syntax-name-variable-color", default: "#e06c75" },
    { suffix: "syntax-name-variable-definition-color", default: "#e5c07b" },
    { suffix: "syntax-name-variable-local-color", default: "#d19a66" },
    { suffix: "syntax-name-variable-special-color", default: "inherit" },
    { suffix: "syntax-number-color", default: "#d19a66" },
    { suffix: "syntax-operator-color", default: "#96c0d8" },
    { suffix: "syntax-processing-instruction-color", default: "#444444", light: "#bbbbbb" },
    { suffix: "syntax-punctuation-color", default: "#abb2bf" },
    { suffix: "syntax-strikethrough-color", default: "inherit" },
    { suffix: "syntax-strikethrough-text-decoration", default: "line-through" },
    { suffix: "syntax-string-color", default: "#98c379" },
    { suffix: "syntax-string-special-color", default: "inherit" },
    { suffix: "syntax-strong-color", default: "inherit" },
    { suffix: "syntax-strong-font-weight", default: "600" },
    { suffix: "syntax-url-color", default: "#aaaaaa", light: "#666666" }
  ], t = !zn(e.options.interface.appearance);
  return n.map((o) => {
    const r = t && o.light ? o.light : o.default;
    return `--ink-internal-${o.suffix}: var(--ink-${o.suffix}, ${r});`;
  });
}, Bn = (e) => [
  P.theme({}, { dark: e })
], En = (e) => e.extensions.map((n) => n.initialValue(e)), ue = (e) => Promise.all(
  e.extensions.map((n) => n.reconfigure(e.options))
), jn = (e) => {
  const n = new Ce();
  return {
    compartment: n,
    initialValue: (t) => n.of(e(t.options)),
    reconfigure: (t) => n.reconfigure(e(t))
  };
}, Tn = (e) => {
  const n = new Ce();
  return {
    compartment: n,
    initialValue: (t) => n.of([]),
    reconfigure: (t) => e(t, n)
  };
}, Vn = () => [
  ...On.map((e) => jn(e)),
  ...Rn.map((e) => Tn(e))
], On = [
  (e) => e.plugins.reduce((t, o) => (o.type === re.Default && t.push(o.value), t), []),
  (e) => {
    const n = e.plugins.reduce((t, o) => (o.type === re.Grammar && t.push(o.value), t), []);
    return pn({
      base: hn,
      codeLanguages: kn,
      extensions: n
    });
  },
  (e) => {
    const n = e.interface.appearance === V.Dark, t = e.interface.appearance === V.Auto;
    return Bn(n || t && Me());
  }
], Rn = [
  async (e, n) => {
    if (e.interface.autocomplete) {
      const { autocomplete: t } = await import("./autocomplete-294208a2.js");
      return n.reconfigure(t(e));
    }
    return n.reconfigure([]);
  },
  async (e, n) => {
    if (e.interface.images) {
      const { images: t } = await import("./images-1efb4104.js");
      return n.reconfigure(t());
    }
    return n.reconfigure([]);
  },
  async (e, n) => {
    if (e.interface.lists) {
      const { lists: t } = await import("./lists-45709764.js");
      return n.reconfigure(t());
    }
    return n.reconfigure([]);
  },
  async (e, n) => {
    if (e.interface.readonly) {
      const { readonly: t } = await import("./readonly-28fcecea.js");
      return n.reconfigure(t());
    }
    return n.reconfigure([]);
  },
  async (e, n) => {
    if (e.interface.spellcheck) {
      const { spellcheck: t } = await import("./spellcheck-9deeebb9.js");
      return n.reconfigure(t());
    }
    return n.reconfigure([]);
  },
  async (e, n) => {
    if (e.vim) {
      const { vim: t } = await import("./vim-96332d1a.js");
      return n.reconfigure(t());
    }
    return n.reconfigure([]);
  }
], ae = () => {
  const e = {
    doc: "",
    files: {
      clipboard: !1,
      dragAndDrop: !1,
      handler: () => {
      },
      injectMarkup: !0,
      types: ["image/*"]
    },
    hooks: {
      afterUpdate: () => {
      },
      beforeUpdate: () => {
      }
    },
    interface: {
      appearance: V.Auto,
      attribution: !0,
      autocomplete: !1,
      images: !1,
      lists: !1,
      readonly: !1,
      spellcheck: !0,
      toolbar: !1
    },
    plugins: [],
    readability: !1,
    selections: [],
    toolbar: {
      bold: !0,
      code: !0,
      codeBlock: !0,
      heading: !0,
      image: !0,
      italic: !0,
      link: !0,
      list: !0,
      orderedList: !0,
      quote: !0,
      taskList: !0,
      upload: !1
    },
    vim: !1
  };
  return {
    doc: "",
    editor: {},
    extensions: Vn(),
    options: e,
    root: ye(),
    target: ye()
  };
}, Nn = (e) => W(ae(), e), fe = (e, n = {}) => {
  const [t, o] = B(Nn({ ...n, doc: e.doc || "", options: e }));
  return [t, o];
}, In = ([e]) => {
  const { editor: n } = e();
  n.destroy();
}, le = ([e]) => {
  const { editor: n } = e();
  n.hasFocus || n.focus();
}, w = (e) => ({ ...{
  block: !1,
  line: !1,
  multiline: !1,
  nodes: [],
  prefix: "",
  prefixStates: [],
  suffix: ""
}, ...e }), qn = {
  [h.Bold]: w({
    nodes: ["StrongEmphasis"],
    prefix: "**",
    suffix: "**"
  }),
  [h.Code]: w({
    nodes: ["InlineCode"],
    prefix: "`",
    suffix: "`"
  }),
  [h.CodeBlock]: w({
    block: !0,
    nodes: ["FencedCode"],
    prefix: "```\n",
    suffix: "\n```"
  }),
  [h.Heading]: w({
    multiline: !0,
    nodes: ["ATXHeading1", "ATXHeading2", "ATXHeading3", "ATXHeading4", "ATXHeading5", "ATXHeading6"],
    prefix: "# ",
    prefixStates: ["# ", "## ", "### ", "#### ", "##### ", "###### ", ""]
  }),
  [h.Image]: w({
    nodes: ["Image"],
    prefix: "![](",
    suffix: ")"
  }),
  [h.Italic]: w({
    nodes: ["Emphasis"],
    prefix: "*",
    suffix: "*"
  }),
  [h.Link]: w({
    nodes: ["Link"],
    prefix: "[](",
    suffix: ")"
  }),
  [h.OrderedList]: w({
    line: !0,
    multiline: !0,
    nodes: ["OrderedList"],
    prefix: "1. "
  }),
  [h.Quote]: w({
    line: !0,
    multiline: !0,
    nodes: ["Blockquote"],
    prefix: "> "
  }),
  [h.TaskList]: w({
    line: !0,
    multiline: !0,
    nodes: ["BulletList"],
    prefix: "- [ ] "
  }),
  [h.List]: w({
    line: !0,
    multiline: !0,
    nodes: ["BulletList"],
    prefix: "- "
  })
}, De = ([e, n], t) => {
  const { editor: o } = e(), r = o.lineBlockAt(t.start), i = o.lineBlockAt(t.end);
  return { start: r.from, end: i.to };
}, Pn = ([e, n], t) => {
  const { editor: o } = e();
  let r = t.start;
  const i = [];
  for (; r <= t.end; ) {
    const l = o.lineBlockAt(r), a = Math.max(r, l.from), s = Math.min(r, l.to);
    i.push({ start: a, end: s }), r = l.to + 1;
  }
  return i;
}, Wn = ([e, n], t) => {
  const { editor: o } = e(), r = o.state.wordAt(t.start)?.from || t.start, i = o.state.wordAt(t.end)?.to || t.end;
  return { start: r, end: i };
}, Fn = ([e, n], t) => t || Z([e, n]).pop() || { start: 0, end: 0 }, He = ([e, n], t) => {
  const { editor: o } = e();
  return o.state.sliceDoc(t.start, t.end);
}, me = ([e, n], t, o) => Un(e(), o).find(({ type: i }) => t.nodes.includes(i.name)), Un = ({ editor: { state: e } }, n) => {
  const t = [];
  return de(e).iterate({
    from: n.start,
    to: n.end,
    enter: ({ type: o, from: r, to: i }) => {
      t.push({ type: o, from: r, to: i });
    }
  }), t;
}, ge = ([e, n], t, o) => {
  const r = He([e, n], o), i = t.prefix.length, l = t.suffix.length * -1 || r.length, a = r.slice(i, l);
  O([e, n], a, o);
}, Xn = ([e, n], t, o) => {
  const r = De([e, n], o), i = me([e, n], t, r);
  if (i) {
    const l = i.from, a = i.to;
    ge([e, n], t, { start: l, end: a });
  } else {
    const l = t.prefix, a = t.suffix;
    G([e, n], { before: l, after: a, selection: r });
  }
}, Kn = ([e, n], t, o) => {
  Pn([e, n], o).forEach((i) => {
    Ae([e, n], t, i);
  });
}, Ae = ([e, n], t, o) => {
  const r = De([e, n], o), i = me([e, n], t, r), l = t.prefixStates.length > 0;
  if (i && l)
    t.prefixStates.find((a, s) => {
      const u = i.from, k = i.to, y = He([e, n], { start: u, end: k }), $ = y.startsWith(a);
      return $ && O([e, n], y.replace(new RegExp(`^${a}`), t.prefixStates[s + 1]), { start: u, end: k }), $;
    });
  else if (i) {
    const a = i.from, s = i.to;
    ge([e, n], t, { start: a, end: s });
  } else {
    const a = t.prefix, s = t.suffix;
    G([e, n], { before: a, after: s, selection: r });
  }
}, Qn = ([e, n], t, o) => {
  const r = me([e, n], t, o);
  if (r) {
    const i = r.from, l = r.to;
    ge([e, n], t, { start: i, end: l });
  } else {
    const { start: i, end: l } = Wn([e, n], o), a = Array.isArray(t.prefix) ? t.prefix[0] : t.prefix, s = t.suffix;
    G([e, n], { before: a, after: s, selection: { start: i, end: l } });
  }
}, ze = ([e, n], t, { selection: o } = {}) => {
  const r = qn[t], i = Fn([e, n], o);
  r.block ? Xn([e, n], r, i) : r.multiline ? Kn([e, n], r, i) : r.line ? Ae([e, n], r, i) : Qn([e, n], r, i);
}, Yn = ([e]) => {
  const { editor: n } = e();
  return n.state.sliceDoc();
}, Be = (e) => {
  const n = e.map((t) => un.fromJSON({ anchor: t.start, head: t.end }));
  return fn.create(n);
}, Zn = (e) => e.ranges.map((t) => ({
  end: t.anchor < t.head ? t.head : t.anchor,
  start: t.head < t.anchor ? t.head : t.anchor
})), Z = ([e]) => {
  const { editor: n } = e();
  return Zn(n.state.selection);
}, O = ([e, n], t, o, r = !1) => {
  const { editor: i } = e();
  let l = o?.start, a = o?.end || o?.start;
  if (typeof l > "u") {
    const u = Z([e, n]).pop();
    l = u.start, a = u.end;
  }
  const s = { changes: { from: l, to: a, insert: t } };
  if (r) {
    const u = l === a ? l + t.length : l, k = l + t.length;
    Object.assign(s, { selection: { anchor: u, head: k } });
  }
  i.dispatch(
    i.state.update(s)
  );
}, Gn = [
  "Blockquote"
], Jn = S.line({ attributes: { class: "cm-blockquote" } }), et = S.line({ attributes: { class: "cm-blockquote-open" } }), nt = S.line({ attributes: { class: "cm-blockquote-close" } }), tt = Se.define((e) => ({
  update: () => ot(e)
}), { decorations: (e) => e.update() }), ot = (e) => {
  const n = new Le(), t = de(e.state);
  for (const o of e.visibleRanges)
    for (let r = o.from; r < o.to; ) {
      const i = e.state.doc.lineAt(r);
      t.iterate({
        enter({ type: l, from: a, to: s }) {
          if (l.name !== "Document" && Gn.includes(l.name)) {
            n.add(i.from, i.from, Jn);
            const u = e.state.doc.lineAt(a), k = e.state.doc.lineAt(s);
            return u.number === i.number && n.add(i.from, i.from, et), k.number === i.number && n.add(i.from, i.from, nt), !1;
          }
        },
        from: i.from,
        to: i.to
      }), r = i.to + 1;
    }
  return n.finish();
}, rt = () => [
  tt
], it = [
  "CodeBlock",
  "FencedCode",
  "HTMLBlock",
  "CommentBlock"
], R = {
  // Prevent spellcheck in all code blocks. The Grammarly extension might not respect these values.
  "data-enable-grammarly": "false",
  "data-gramm": "false",
  "data-grammarly-skip": "true",
  spellcheck: "false"
}, at = S.line({ attributes: { ...R, class: "cm-codeblock" } }), lt = S.line({ attributes: { ...R, class: "cm-codeblock-open" } }), st = S.line({ attributes: { ...R, class: "cm-codeblock-close" } }), ct = S.mark({ attributes: { ...R, class: "cm-code" } }), dt = S.mark({ attributes: { ...R, class: "cm-code cm-code-open" } }), ut = S.mark({ attributes: { ...R, class: "cm-code cm-code-close" } }), ft = Se.define((e) => ({
  update: () => mt(e)
}), { decorations: (e) => e.update() }), mt = (e) => {
  const n = new Le(), t = de(e.state);
  for (const o of e.visibleRanges)
    for (let r = o.from; r < o.to; ) {
      const i = e.state.doc.lineAt(r);
      let l;
      t.iterate({
        enter({ type: a, from: s, to: u }) {
          if (a.name !== "Document")
            if (it.includes(a.name)) {
              n.add(i.from, i.from, at);
              const k = e.state.doc.lineAt(s), y = e.state.doc.lineAt(u);
              return k.number === i.number && n.add(i.from, i.from, lt), y.number === i.number && n.add(i.from, i.from, st), !1;
            } else
              a.name === "InlineCode" ? l = { from: s, to: u, innerFrom: s, innerTo: u } : a.name === "CodeMark" && (s === l.from ? (l.innerFrom = u, n.add(s, u, dt)) : u === l.to && (l.innerTo = s, n.add(l.innerFrom, l.innerTo, ct), n.add(s, u, ut)));
        },
        from: i.from,
        to: i.to
      }), r = i.to + 1;
    }
  return n.finish();
}, gt = () => [
  ft
], pt = () => [
  P.editorAttributes.of({
    class: "ink-mde-container"
  }),
  P.contentAttributes.of({
    class: "ink-mde-editor-content"
  })
  // Todo: Maybe open a PR to add scrollerAttributes?
], ht = () => [
  ...pt()
], kt = [
  {
    key: "Tab",
    run: ({ state: e, dispatch: n }) => e.selection.ranges.some((t) => !t.empty) ? _n({ state: e, dispatch: n }) : (n(
      e.update(e.replaceSelection("  "), {
        scrollIntoView: !0,
        annotations: mn.userEvent.of("input")
      })
    ), !0),
    shift: wn
  }
], bt = () => bn.of([
  ...kt,
  ...yn,
  ...$n
]), xt = () => P.lineWrapping, vt = () => [
  xn(
    vn.define([
      // ordered by lowest to highest precedence
      {
        tag: d.atom,
        color: "var(--ink-internal-syntax-atom-color)"
      },
      {
        tag: d.meta,
        color: "var(--ink-internal-syntax-meta-color)"
      },
      // emphasis types
      {
        tag: d.emphasis,
        color: "var(--ink-internal-syntax-emphasis-color)",
        fontStyle: "var(--ink-internal-syntax-emphasis-font-style)"
      },
      {
        tag: d.strong,
        color: "var(--ink-internal-syntax-strong-color)",
        fontWeight: "var(--ink-internal-syntax-strong-font-weight)"
      },
      {
        tag: d.strikethrough,
        color: "var(--ink-internal-syntax-strikethrough-color)",
        textDecoration: "var(--ink-internal-syntax-strikethrough-text-decoration)"
      },
      // comment group
      {
        tag: d.comment,
        color: "var(--ink-internal-syntax-comment-color)",
        fontStyle: "var(--ink-internal-syntax-comment-font-style)"
      },
      // monospace
      {
        tag: d.monospace,
        color: "var(--ink-internal-syntax-code-color)",
        fontFamily: "var(--ink-internal-syntax-code-font-family)"
      },
      // name group
      {
        tag: d.name,
        color: "var(--ink-internal-syntax-name-color)"
      },
      {
        tag: d.labelName,
        color: "var(--ink-internal-syntax-name-label-color)"
      },
      {
        tag: d.propertyName,
        color: "var(--ink-internal-syntax-name-property-color)"
      },
      {
        tag: d.definition(d.propertyName),
        color: "var(--ink-internal-syntax-name-property-definition-color)"
      },
      {
        tag: d.variableName,
        color: "var(--ink-internal-syntax-name-variable-color)"
      },
      {
        tag: d.definition(d.variableName),
        color: "var(--ink-internal-syntax-name-variable-definition-color)"
      },
      {
        tag: d.local(d.variableName),
        color: "var(--ink-internal-syntax-name-variable-local-color)"
      },
      {
        tag: d.special(d.variableName),
        color: "var(--ink-internal-syntax-name-variable-special-color)"
      },
      // headings
      {
        tag: d.heading,
        color: "var(--ink-internal-syntax-heading-color)",
        fontWeight: "var(--ink-internal-syntax-heading-font-weight)"
      },
      {
        tag: d.heading1,
        color: "var(--ink-internal-syntax-heading1-color)",
        fontSize: "var(--ink-internal-syntax-heading1-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading1-font-weight)"
      },
      {
        tag: d.heading2,
        color: "var(--ink-internal-syntax-heading2-color)",
        fontSize: "var(--ink-internal-syntax-heading2-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading2-font-weight)"
      },
      {
        tag: d.heading3,
        color: "var(--ink-internal-syntax-heading3-color)",
        fontSize: "var(--ink-internal-syntax-heading3-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading3-font-weight)"
      },
      {
        tag: d.heading4,
        color: "var(--ink-internal-syntax-heading4-color)",
        fontSize: "var(--ink-internal-syntax-heading4-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading4-font-weight)"
      },
      {
        tag: d.heading5,
        color: "var(--ink-internal-syntax-heading5-color)",
        fontSize: "var(--ink-internal-syntax-heading5-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading5-font-weight)"
      },
      {
        tag: d.heading6,
        color: "var(--ink-internal-syntax-heading6-color)",
        fontSize: "var(--ink-internal-syntax-heading6-font-size)",
        fontWeight: "var(--ink-internal-syntax-heading6-font-weight)"
      },
      // contextual tag types
      {
        tag: d.keyword,
        color: "var(--ink-internal-syntax-keyword-color)"
      },
      {
        tag: d.number,
        color: "var(--ink-internal-syntax-number-color)"
      },
      {
        tag: d.operator,
        color: "var(--ink-internal-syntax-operator-color)"
      },
      {
        tag: d.punctuation,
        color: "var(--ink-internal-syntax-punctuation-color)"
      },
      {
        tag: d.link,
        color: "var(--ink-internal-syntax-link-color)"
      },
      {
        tag: d.url,
        color: "var(--ink-internal-syntax-url-color)"
      },
      // string group
      {
        tag: d.string,
        color: "var(--ink-internal-syntax-string-color)"
      },
      {
        tag: d.special(d.string),
        color: "var(--ink-internal-syntax-string-special-color)"
      },
      // processing instructions
      {
        tag: d.processingInstruction,
        color: "var(--ink-internal-syntax-processing-instruction-color)"
      }
    ])
  )
], yt = (e) => {
  if (e.length > 0)
    return Be(e);
}, Ee = (e) => gn.create({
  doc: e.options.doc,
  selection: yt(e.options.selections),
  extensions: [
    rt(),
    gt(),
    Cn(),
    ht(),
    bt(),
    xt(),
    vt(),
    ...En(e)
  ]
}), $t = ([e, n], t) => {
  n(W(e(), { options: { doc: t } })), e().editor.setState(Ee(e()));
}, _t = ([e]) => e().options, wt = async ([e, n], t) => {
  const o = n(W(e(), { options: t })), r = await ue(o);
  o.editor.dispatch({ effects: r });
}, je = (e, n = {}) => {
  if (n.selections)
    return Te(e, n.selections);
  if (n.selection)
    return se(e, n.selection);
  if (n.at)
    return Ct(e, n.at);
}, Ct = (e, n) => {
  const [t] = e;
  if (n === ie.Start)
    return se(e, { start: 0, end: 0 });
  if (n === ie.End) {
    const o = t().editor.state.doc.length;
    return se(e, { start: o, end: o });
  }
}, Te = ([e], n) => {
  const { editor: t } = e();
  t.dispatch(
    t.state.update({
      selection: Be(n)
    })
  );
}, se = (e, n) => Te(e, [n]), Lt = ([e], n) => {
  const { editor: t } = e();
  t.dispatch(
    t.state.update({
      changes: {
        from: 0,
        to: t.state.doc.length,
        insert: n
      }
    })
  );
}, G = ([e, n], { after: t, before: o, selection: r }) => {
  const { editor: i } = e(), l = r || Z([e, n]).pop() || { start: 0, end: 0 }, a = i.state.sliceDoc(l.start, l.end);
  O([e, n], `${o}${a}${t}`, l), je([e, n], { selections: [{ start: l.start + o.length, end: l.end + o.length }] });
}, Ve = (e) => ({
  destroy: In.bind(void 0, e),
  focus: le.bind(void 0, e),
  format: ze.bind(void 0, e),
  getDoc: Yn.bind(void 0, e),
  insert: O.bind(void 0, e),
  load: $t.bind(void 0, e),
  options: _t.bind(void 0, e),
  reconfigure: wt.bind(void 0, e),
  select: je.bind(void 0, e),
  selections: Z.bind(void 0, e),
  update: Lt.bind(void 0, e),
  wrap: G.bind(void 0, e)
}), St = `.ink-drop-zone{align-items:center;background-color:#00000080;color:var(--ink-internal-color);display:flex;inset:0;justify-content:center;position:var(--ink-internal-modal-position);z-index:100}.ink-drop-zone:not(.visible){display:none}.ink-drop-zone-modal{background-color:var(--ink-internal-block-background-color);border-radius:var(--ink-internal-border-radius);box-sizing:border-box;height:100%;max-height:20rem;max-width:40rem;padding:1rem;position:relative;width:100%}.ink-drop-zone-hide{cursor:pointer;height:1.75rem;position:absolute;right:.25rem;top:.25rem;width:1.75rem}.ink-drop-zone-hide svg{background-color:var(--ink-internal-block-background-color)}.ink-drop-zone-droppable-area{align-items:center;border:.2rem dashed var(--ink-internal-color);border-radius:.125rem;box-sizing:border-box;display:flex;flex-direction:column;font-size:1.25em;gap:1rem;height:100%;justify-content:center;padding:1rem;text-align:center}.ink-drop-zone-file-preview{align-items:center;display:flex;flex-wrap:wrap;gap:.5rem;max-width:25.5rem}.ink-drop-zone-file-preview-image{border:.125rem solid #222;border-radius:.125rem;box-sizing:border-box;height:6rem;object-fit:cover;padding:.5rem;width:6rem}
`, Mt = /* @__PURE__ */ m("<span>uploading files...</span>", 2), Dt = /* @__PURE__ */ m('<div class="ink-drop-zone"><style></style><div class="ink-drop-zone-modal"><div class="ink-drop-zone-droppable-area"><div class="ink-drop-zone-file-preview"></div><!#><!/></div><div class="ink-drop-zone-hide"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div></div></div>', 18), Ht = /* @__PURE__ */ m('<img class="ink-drop-zone-file-preview-image">', 1), At = /* @__PURE__ */ m("<span>drop files here</span>", 2), zt = () => {
  const [e, n] = B(0), [t, o] = B([]), [r, i] = B(!1), [l, a] = B(!1), [s, u] = N(), k = () => {
    a(!1);
  }, y = (p) => {
    if (s().options.files.dragAndDrop) {
      p.preventDefault(), p.stopPropagation();
      const v = p.dataTransfer;
      v?.files ? F(v.files) : (n(0), a(!1), o([]));
    }
  }, $ = (p) => {
    s().options.files.dragAndDrop && (p.preventDefault(), n(e() + 1), a(!0));
  }, C = (p) => {
    s().options.files.dragAndDrop && (p.preventDefault(), n(e() - 1), e() === 0 && a(!1));
  }, M = (p) => {
    s().options.files.dragAndDrop && (p.preventDefault(), a(!0));
  }, H = (p) => {
    s().options.files.dragAndDrop && (p.preventDefault(), n(0), a(!1));
  }, E = (p) => {
    if (s().options.files.clipboard) {
      p.preventDefault();
      const v = p.clipboardData;
      v?.files && v.files.length > 0 && F(v.files);
    }
  }, F = (p) => {
    Array.from(p).forEach((v) => {
      o([...t(), v]);
    }), i(!0), a(!0), Promise.resolve(s().options.files.handler(p)).then((v) => {
      if (s().options.files.injectMarkup && v) {
        const L = `![](${v})`;
        O([s, u], L);
      }
    }).finally(() => {
      n(0), i(!1), a(!1), o([]);
    });
  };
  return we(() => {
    document.addEventListener("dragenter", $), document.addEventListener("dragleave", C), document.addEventListener("dragover", M), document.addEventListener("drop", H), s().root.addEventListener("paste", E);
  }), an(() => {
    document.removeEventListener("dragenter", $), document.removeEventListener("dragleave", C), document.removeEventListener("dragover", M), document.removeEventListener("drop", H), s().root.removeEventListener("paste", E);
  }), (() => {
    const p = f(Dt), v = p.firstChild, L = v.nextSibling, j = L.firstChild, I = j.firstChild, J = I.nextSibling, [ee, U] = b(J.nextSibling), ne = j.nextSibling;
    return v.textContent = St, j.addEventListener("drop", y), g(I, c(ln, {
      get each() {
        return t().slice(0, 8);
      },
      children: (X) => (() => {
        const q = f(Ht);
        return oe((A) => {
          const D = X.name, K = URL.createObjectURL(X);
          return D !== A._v$ && ve(q, "alt", A._v$ = D), K !== A._v$2 && ve(q, "src", A._v$2 = K), A;
        }, {
          _v$: void 0,
          _v$2: void 0
        }), q;
      })()
    })), g(j, c(x, {
      get when() {
        return r();
      },
      get fallback() {
        return f(At);
      },
      get children() {
        return f(Mt);
      }
    }), ee, U), ne.$$click = k, oe(() => p.classList.toggle("visible", !!l())), ce(), p;
  })();
};
$e(["click"]);
const Bt = ([e, n]) => {
  const t = new P({
    dispatch: (o) => {
      const { options: r } = e(), i = o.newDoc.toString();
      r.hooks.beforeUpdate(i), t.update([o]), o.docChanged && (n({ ...e(), doc: i }), r.hooks.afterUpdate(i));
    },
    state: Ee(e())
  });
  return t;
}, Et = () => {
  const [e, n] = N(), t = Bt([e, n]);
  return n(W(e(), {
    editor: t
  })), ue(e()).then((o) => {
    t.dispatch({
      effects: o
    });
  }), t.dom;
}, jt = /* @__PURE__ */ m('<button class="ink-button" type="button"></button>', 2), _ = (e) => (() => {
  const n = f(jt);
  return n.$$click = (t) => e.onclick(t), g(n, () => e.children), ce(), n;
})();
$e(["click"]);
const Tt = `.ink-mde .ink-mde-toolbar{background-color:var(--ink-internal-block-background-color);color:inherit;display:flex;flex-shrink:0;overflow-x:auto;padding:.25rem}.ink-mde .ink-mde-toolbar .ink-mde-container{display:flex;gap:2rem}.ink-mde .ink-mde-toolbar-group{display:flex}.ink-mde .ink-mde-toolbar .ink-button{align-items:center;background:none;border:none;border-radius:var(--ink-internal-border-radius);color:inherit;cursor:pointer;display:flex;height:2.25rem;justify-content:center;padding:.4rem;width:2.25rem}.ink-mde .ink-mde-toolbar .ink-button:hover{background-color:var(--ink-internal-block-background-color-on-hover)}.ink-mde .ink-mde-toolbar .ink-button>*{align-items:center;display:flex;height:100%}
`, Vt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4V10M6 16V10M6 10H14M14 10V4M14 10V16"></path></svg>', 4), Ot = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M6.5 10H10.5C12.1569 10 13.5 11.3431 13.5 13C13.5 14.6569 12.1569 16 10.5 16H6.5V4H9.5C11.1569 4 12.5 5.34315 12.5 7C12.5 8.65686 11.1569 10 9.5 10"></path></svg>', 4), Rt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4L9 16M13 4H9M7 16H11"></path></svg>', 4), Nt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M2.00257 16H17.9955M2.00055 4H18M7 10H18.0659M2 8.5V11.4999C2.4 11.5 2.5 11.5 2.5 11.5V11V10.5M4 8.5V11.4999H4.5V11V10.5"></path></svg>', 4), It = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M13 4L7 16"></path><path d="M5 7L2 10L5 13"></path><path d="M15 7L18 10L15 13"></path></svg>', 8), qt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 4L8 6"></path></svg>', 4), Pt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 16H17.8294"></path><path d="M2 16H4"></path><path d="M7 10H17.8294"></path><path d="M2 10H4"></path><path d="M7 4H17.8294"></path><path d="M2 4H4"></path></svg>', 14), Wt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 16H18"></path><path d="M2 17.0242C2.48314 17.7569 3.94052 17.6154 3.99486 16.7919C4.05315 15.9169 3.1975 16.0044 2.99496 16.0044M2.0023 14.9758C2.48544 14.2431 3.94282 14.3846 3.99716 15.2081C4.05545 16.0831 3.1998 16.0002 2.99726 16.0002"></path><path d="M7 10H18"></path><path d="M2.00501 11.5H4M2.00193 8.97562C2.48449 8.24319 3.9401 8.38467 3.99437 9.20777C4.05259 10.0825 2.04342 10.5788 2 11.4996"></path><path d="M7 4H18"></path><path d="M2 5.5H4M2.99713 5.49952V2.5L2.215 2.93501"></path></svg>', 14), Ft = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 16H17.8294"></path><path d="M5 15L3 17L2 16"></path><path d="M7 10H17.8294"></path><path d="M5 9L3 11L2 10"></path><path d="M7 4H17.8294"></path><path d="M5 3L3 5L2 4"></path></svg>', 14), Ut = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M9.12127 10.881C10.02 11.78 11.5237 11.7349 12.4771 10.7813L15.2546 8.00302C16.2079 7.04937 16.253 5.54521 15.3542 4.6462C14.4555 3.74719 12.9512 3.79174 11.9979 4.74539L10.3437 6.40007M10.8787 9.11903C9.97997 8.22002 8.47626 8.26509 7.52288 9.21874L4.74545 11.997C3.79208 12.9506 3.74701 14.4548 4.64577 15.3538C5.54452 16.2528 7.04876 16.2083 8.00213 15.2546L9.65633 13.5999"></path></svg>', 4), Xt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="16" height="12" rx="1"></rect><path d="M7.42659 7.67597L13.7751 13.8831M2.00208 12.9778L7.42844 7.67175"></path><path d="M11.9119 12.0599L14.484 9.54443L17.9973 12.9785"></path><path d="M10.9989 7.95832C11.551 7.95832 11.9986 7.52072 11.9986 6.98092C11.9986 6.44113 11.551 6.00354 10.9989 6.00354C10.4468 6.00354 9.99921 6.44113 9.99921 6.98092C9.99921 7.52072 10.4468 7.95832 10.9989 7.95832Z"></path></svg>', 10), Kt = /* @__PURE__ */ m('<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-miterlimit="5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13V4M10 4L13 7M10 4L7 7"></path><path d="M2 13V15C2 15.5523 2.44772 16 3 16H17C17.5523 16 18 15.5523 18 15V13"></path></svg>', 6), Qt = /* @__PURE__ */ m('<input type="file">', 1), Yt = /* @__PURE__ */ m('<div class="ink-mde-toolbar"><style></style><div class="ink-mde-container"><div class="ink-mde-toolbar-group"><!#><!/><!#><!/><!#><!/></div><div class="ink-mde-toolbar-group"><!#><!/><!#><!/><!#><!/></div><div class="ink-mde-toolbar-group"><!#><!/><!#><!/><!#><!/></div><div class="ink-mde-toolbar-group"><!#><!/><!#><!/><!#><!/></div></div></div>', 38), Zt = () => {
  const [e, n] = N(), [t, o] = B(), r = (a) => {
    ze([e, n], a), le([e, n]);
  }, i = (a) => {
    const s = a.target;
    s?.files && Promise.resolve(e().options.files.handler(s.files)).then((u) => {
      const k = `![](${u})`;
      O([e, n], k), le([e, n]);
    });
  }, l = () => {
    t()?.click();
  };
  return (() => {
    const a = f(Yt), s = a.firstChild, u = s.nextSibling, k = u.firstChild, y = k.firstChild, [$, C] = b(y.nextSibling), M = $.nextSibling, [H, E] = b(M.nextSibling), F = H.nextSibling, [p, v] = b(F.nextSibling), L = k.nextSibling, j = L.firstChild, [I, J] = b(j.nextSibling), ee = I.nextSibling, [U, ne] = b(ee.nextSibling), X = U.nextSibling, [q, A] = b(X.nextSibling), D = L.nextSibling, K = D.firstChild, [he, Ie] = b(K.nextSibling), qe = he.nextSibling, [ke, Pe] = b(qe.nextSibling), We = ke.nextSibling, [Fe, Ue] = b(We.nextSibling), Q = D.nextSibling, Xe = Q.firstChild, [be, Ke] = b(Xe.nextSibling), Qe = be.nextSibling, [xe, Ye] = b(Qe.nextSibling), Ze = xe.nextSibling, [Ge, Je] = b(Ze.nextSibling);
    return s.textContent = Tt, g(k, c(x, {
      get when() {
        return e().options.toolbar.heading;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Heading),
          get children() {
            return f(Vt);
          }
        });
      }
    }), $, C), g(k, c(x, {
      get when() {
        return e().options.toolbar.bold;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Bold),
          get children() {
            return f(Ot);
          }
        });
      }
    }), H, E), g(k, c(x, {
      get when() {
        return e().options.toolbar.italic;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Italic),
          get children() {
            return f(Rt);
          }
        });
      }
    }), p, v), g(L, c(x, {
      get when() {
        return e().options.toolbar.quote;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Quote),
          get children() {
            return f(Nt);
          }
        });
      }
    }), I, J), g(L, c(x, {
      get when() {
        return e().options.toolbar.codeBlock;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.CodeBlock),
          get children() {
            return f(It);
          }
        });
      }
    }), U, ne), g(L, c(x, {
      get when() {
        return e().options.toolbar.code;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Code),
          get children() {
            return f(qt);
          }
        });
      }
    }), q, A), g(D, c(x, {
      get when() {
        return e().options.toolbar.list;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.List),
          get children() {
            return f(Pt);
          }
        });
      }
    }), he, Ie), g(D, c(x, {
      get when() {
        return e().options.toolbar.orderedList;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.OrderedList),
          get children() {
            return f(Wt);
          }
        });
      }
    }), ke, Pe), g(D, c(x, {
      get when() {
        return e().options.toolbar.taskList;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.TaskList),
          get children() {
            return f(Ft);
          }
        });
      }
    }), Fe, Ue), g(Q, c(x, {
      get when() {
        return e().options.toolbar.link;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Link),
          get children() {
            return f(Ut);
          }
        });
      }
    }), be, Ke), g(Q, c(x, {
      get when() {
        return e().options.toolbar.image;
      },
      get children() {
        return c(_, {
          onclick: () => r(h.Image),
          get children() {
            return f(Xt);
          }
        });
      }
    }), xe, Ye), g(Q, c(x, {
      get when() {
        return e().options.toolbar.upload;
      },
      get children() {
        return c(_, {
          onclick: l,
          get children() {
            return [f(Kt), (() => {
              const Y = f(Qt);
              return _e(o, Y), Y.addEventListener("change", i), Y.style.setProperty("display", "none"), Y;
            })()];
          }
        });
      }
    }), Ge, Je), a;
  })();
}, pe = 225, Gt = (e, n = pe) => {
  const t = no(e, n), o = to(e), r = eo(e), i = Jt(e);
  return [t, o, r, i].join(" | ");
}, Jt = (e) => `${oo(e)} chars`, eo = (e) => `${ro(e)} lines`, no = (e, n = pe) => {
  const t = io(e, n), o = Math.floor(t), r = Math.floor(t % 1 * 60);
  return o === 0 ? `${r}s read` : `${o}m ${r}s to read`;
}, to = (e) => `${Oe(e)} words`, oo = (e) => e.length, ro = (e) => e.split(/\n/).length, io = (e, n = pe) => Oe(e) / n, Oe = (e) => {
  const n = e.replace(/[']/g, "").replace(/[^\w\d]+/g, " ").trim();
  return n ? n.split(/\s+/).length : 0;
}, ao = /* @__PURE__ */ m('<div class="ink-mde-readability"><span></span></div>', 4), lo = /* @__PURE__ */ m("<span>&nbsp;|</span>", 2), so = /* @__PURE__ */ m('<div class="ink-mde-attribution"><span>&nbsp;powered by <a class="ink-mde-attribution-link" href="https://github.com/voracious/ink-mde" rel="noopener noreferrer" target="_blank">ink-mde</a></span></div>', 6), co = /* @__PURE__ */ m('<div class="ink-mde-details"><div class="ink-mde-container"><div class="ink-mde-details-content"><!#><!/><!#><!/><!#><!/></div></div></div>', 12), uo = () => {
  const [e] = N();
  return (() => {
    const n = f(co), t = n.firstChild, o = t.firstChild, r = o.firstChild, [i, l] = b(r.nextSibling), a = i.nextSibling, [s, u] = b(a.nextSibling), k = s.nextSibling, [y, $] = b(k.nextSibling);
    return g(o, c(x, {
      get when() {
        return e().options.readability;
      },
      get children() {
        const C = f(ao), M = C.firstChild;
        return g(M, () => Gt(e().doc)), C;
      }
    }), i, l), g(o, c(x, {
      get when() {
        return en(() => !!e().options.readability)() && e().options.interface.attribution;
      },
      get children() {
        return f(lo);
      }
    }), s, u), g(o, c(x, {
      get when() {
        return e().options.interface.attribution;
      },
      get children() {
        return f(so);
      }
    }), y, $), n;
  })();
}, fo = `.ink-mde{border:2px solid var(--ink-internal-block-background-color);border-radius:var(--ink-internal-border-radius);color:var(--ink-internal-color, inherit);display:flex;flex-direction:var(--ink-internal-flex-direction, column)}.ink-mde .cm-tooltip{background-color:var(--ink-internal-block-background-color);border-radius:var(--ink-internal-border-radius);font-family:inherit;padding:.25rem}.ink-mde .cm-tooltip.cm-tooltip-autocomplete ul{font-family:inherit}.ink-mde .cm-tooltip.cm-tooltip-autocomplete ul li.ink-tooltip-option{border-radius:var(--ink-internal-border-radius);padding:.25rem}.ink-mde .cm-tooltip.cm-tooltip-autocomplete ul li.ink-tooltip-option[aria-selected]{background-color:#96969640}.ink-mde .cm-completionLabel{font-family:inherit}.ink-mde,.ink-mde *{box-sizing:border-box}.ink-mde,.ink-mde .ink-mde-editor{display:flex;flex-direction:column;flex-grow:1;flex-shrink:1;min-height:0}.ink-mde .ink-mde-editor{overflow:auto;padding:.5rem}.ink-mde .ink-mde-toolbar,.ink-mde .ink-mde-details{display:flex;flex-grow:0;flex-shrink:0}.ink-mde .ink-mde-details{background-color:var(--ink-internal-block-background-color);display:flex;padding:.5rem}.ink-mde .ink-mde-details-content{color:inherit;display:flex;filter:brightness(.75);flex-wrap:wrap;font-size:.75em;justify-content:flex-end}.ink-mde .ink-mde-attribution{display:flex;justify-content:flex-end}.ink-mde .ink-mde-attribution-link{color:currentColor;font-weight:600;text-decoration:none}.ink-mde .ink-mde-container{margin-left:auto;margin-right:auto;width:100%}.ink-mde .ink-mde-task-toggle{cursor:pointer;height:1rem;line-height:2em;margin:0 .25rem 0 0;position:relative;top:-1px;vertical-align:middle;width:1rem}.ink-mde .cm-editor{display:flex;flex-direction:column;position:relative}.ink-mde .cm-scroller{align-items:flex-start;display:flex;font-family:var(--ink-internal-font-family);font-size:var(--ink-internal-editor-font-size);line-height:var(--ink-internal-editor-line-height);overflow-x:auto;position:relative}.ink-mde .cm-content{display:block;flex-grow:2;flex-shrink:0;margin:0;outline:none;padding:0;white-space:pre;word-wrap:normal}.ink-mde .cm-lineWrapping{flex-shrink:1;overflow-wrap:anywhere;white-space:break-spaces;word-break:break-word}.ink-mde .cm-line{font-family:var(--ink-internal-font-family);padding:0}.ink-mde .cm-line.cm-blockquote{background-color:var(--ink-internal-block-background-color);border-left:.25rem solid currentColor;padding:0 var(--ink-internal-block-padding)}.ink-mde .cm-line.cm-blockquote.cm-blockquote-open{border-top-left-radius:var(--ink-internal-border-radius);border-top-right-radius:var(--ink-internal-border-radius);padding-top:var(--ink-internal-block-padding)}.ink-mde .cm-line.cm-blockquote.cm-blockquote-close{border-bottom-left-radius:var(--ink-internal-border-radius);border-bottom-right-radius:var(--ink-internal-border-radius);padding-bottom:var(--ink-internal-block-padding)}.ink-mde .cm-line.cm-codeblock{background-color:var(--ink-internal-block-background-color);font-family:var(--ink-internal-code-font-family);padding:0 var(--ink-internal-block-padding)}.ink-mde .cm-line.cm-codeblock.cm-codeblock-open{border-radius:var(--ink-internal-border-radius) var(--ink-internal-border-radius) 0 0;padding-top:var(--ink-internal-block-padding)}.ink-mde .cm-line.cm-codeblock.cm-codeblock-close{border-radius:0 0 var(--ink-internal-border-radius) var(--ink-internal-border-radius);padding-bottom:var(--ink-internal-block-padding)}.ink-mde .cm-line .cm-code{background-color:var(--ink-internal-block-background-color);font-family:var(--ink-internal-code-font-family);padding:var(--ink-internal-inline-padding) 0}.ink-mde .cm-line .cm-code.cm-code-open{border-radius:var(--ink-internal-border-radius) 0 0 var(--ink-internal-border-radius);padding-left:var(--ink-internal-inline-padding)}.ink-mde .cm-line .cm-code.cm-code-close{border-radius:0 var(--ink-internal-border-radius) var(--ink-internal-border-radius) 0;padding-right:var(--ink-internal-inline-padding)}.ink-mde .cm-image-backdrop{background-color:var(--ink-internal-block-background-color)}
`, mo = /* @__PURE__ */ m("<style> </style>", 2), go = () => {
  const [e] = N(), [n, t] = B(te(e()));
  return sn(() => {
    t(te(e()));
  }), we(() => {
    const o = window.matchMedia("(prefers-color-scheme: dark)"), r = (i) => {
      const {
        editor: l,
        root: a
      } = e();
      a.isConnected ? ue(e()).then((s) => {
        l.dispatch({
          effects: s
        }), t(te(e()));
      }) : o.removeEventListener("change", r);
    };
    o.addEventListener("change", r);
  }), (() => {
    const o = f(mo), r = o.firstChild;
    return oe(() => r.data = `.ink {
  ${n().join(`
  `)}
}
${fo}`), o;
  })();
}, po = /* @__PURE__ */ m('<div class="ink ink-mde"><!#><!/><!#><!/><!#><!/><div class="ink-mde-editor"></div><!#><!/></div>', 12), ho = () => {
  const [e, n] = N(), t = (o) => {
    n(W(e(), {
      root: o
    }));
  };
  return (() => {
    const o = f(po), r = o.firstChild, [i, l] = b(r.nextSibling), a = i.nextSibling, [s, u] = b(a.nextSibling), k = s.nextSibling, [y, $] = b(k.nextSibling), C = y.nextSibling, M = C.nextSibling, [H, E] = b(M.nextSibling);
    return _e(t, o), nn(o, tn(Mn), !1, !0), g(o, c(go, {}), i, l), g(o, c(x, {
      get when() {
        return e().options.files.clipboard || e().options.files.dragAndDrop;
      },
      get children() {
        return c(zt, {});
      }
    }), s, u), g(o, c(x, {
      get when() {
        return e().options.interface.toolbar;
      },
      get children() {
        return c(Zt, {});
      }
    }), y, $), g(C, c(Et, {})), g(o, c(x, {
      get when() {
        return e().options.readability || e().options.interface.attribution;
      },
      get children() {
        return c(uo, {
          store: [e, n]
        });
      }
    }), H, E), ce(), o;
  })();
}, Re = cn([() => ae(), (e) => typeof e == "function" ? e(ae()) : e]), ko = (e) => c(Re.Provider, {
  get value() {
    return e.store;
  },
  get children() {
    return e.children;
  }
}), N = () => dn(Re), Ne = (e) => c(ko, {
  get store() {
    return e.store;
  },
  get children() {
    return c(ho, {
      get store() {
        return e.store;
      }
    });
  }
}), Ho = (e) => e, bo = (e, n = {}) => {
  const t = fe(n);
  return vo(), on(() => c(Ne, {
    store: t
  }), e), Ve(t);
}, Ao = (e, n = {}) => e.querySelector(Sn) ? bo(e, n) : xo(e, n), xo = (e, n = {}) => {
  const t = fe(n);
  return rn(() => c(Ne, {
    store: t
  }), e), Ve(t);
}, zo = (e = {}) => (fe(e), ""), vo = () => {
  let e, n;
  e = window._$HY || (window._$HY = {
    events: [],
    completed: /* @__PURE__ */ new WeakSet(),
    r: {}
  }), n = (t) => t && t.hasAttribute && (t.hasAttribute("data-hk") ? t : n(t.host && t.host instanceof Node ? t.host : t.parentNode)), ["click", "input"].forEach((t) => document.addEventListener(t, (o) => {
    let r = o.composedPath && o.composedPath()[0] || o.target, i = n(r);
    i && !e.completed.has(i) && e.events.push([i, o]);
  })), e.init = (t, o) => {
    e.r[t] = [new Promise((r, i) => o = r), o];
  }, e.set = (t, o, r) => {
    (r = e.r[t]) && r[1](o), e.r[t] = [o];
  }, e.unset = (t) => {
    delete e.r[t];
  }, e.load = (t, o) => {
    if (o = e.r[t])
      return o[0];
  };
};
export {
  V as Appearance,
  An as Extensions,
  h as Markup,
  re as PluginType,
  ie as Selection,
  Ao as default,
  Ho as defineOptions,
  bo as hydrate,
  Ao as ink,
  xo as render,
  zo as renderToString,
  vo as solidPrepareForHydration
};
//# sourceMappingURL=client.js.map
