import { ink as s, renderToString as r } from "ink-mde";
import { defineComponent as a, openBlock as d, createElementBlock as p } from "vue";
const h = a({
  name: "InkMde",
  emits: ["update:modelValue"],
  props: {
    modelValue: {
      type: String
    },
    options: {
      type: Object
    }
  },
  data() {
    return {
      html: "",
      instance: void 0
    };
  },
  watch: {
    modelValue(t) {
      var n, e;
      ((n = this.instance) == null ? void 0 : n.getDoc()) !== t && ((e = this.instance) == null || e.update(t));
    },
    options: {
      deep: !0,
      handler(t, n) {
        var e;
        (e = this.instance) == null || e.reconfigure(t);
      }
    }
  },
  methods: {
    tryInit() {
      var t;
      this.$refs.ink && !this.instance && (this.instance = s(this.$refs.ink, {
        ...this.options,
        doc: this.modelValue,
        hooks: {
          ...(t = this.options) == null ? void 0 : t.hooks,
          afterUpdate: (n) => {
            var e, i;
            this.$emit("update:modelValue", n), (i = (e = this.options) == null ? void 0 : e.hooks) != null && i.afterUpdate && this.options.hooks.afterUpdate(n);
          }
        }
      }), this.$refs.ink.addEventListener("input", (n) => {
        n.stopPropagation();
      }), this.instance.focus());
    }
  },
  created() {
    ({}).VITE_SSR && (this.html = r(this.options));
  },
  mounted() {
    this.tryInit();
  },
  updated() {
    this.tryInit();
  }
}), c = (t, n) => {
  const e = t.__vccOpts || t;
  for (const [i, o] of n)
    e[i] = o;
  return e;
}, f = ["innerHTML"];
function l(t, n, e, i, o, u) {
  return d(), p("div", {
    ref: "ink",
    innerHTML: t.html
  }, null, 8, f);
}
const _ = /* @__PURE__ */ c(h, [["render", l]]);
export {
  _ as default
};
//# sourceMappingURL=client.js.map
