import { bM as b, k as v, bN as m, h as _, D as i, a7 as k } from "./index-BxjwuJ6T.js";
function h(e, l, u = l) {
  var s = /* @__PURE__ */ new WeakSet();
  b(e, "input", async (r) => {
    var a = r ? e.defaultValue : e.value;
    if (a = t(e) ? o(a) : a, u(a), v !== null && s.add(v), await m(), a !== (a = l())) {
      var d = e.selectionStart, f = e.selectionEnd, n = e.value.length;
      if (e.value = a ?? "", f !== null) {
        var c = e.value.length;
        d === f && f === n && c > n ? (e.selectionStart = c, e.selectionEnd = c) : (e.selectionStart = d, e.selectionEnd = Math.min(f, c));
      }
    }
  }), // If we are hydrating and the value has since changed,
  // then use the updated value from the input instead.
  (_ && e.defaultValue !== e.value || // If defaultValue is set, then value == defaultValue
  // TODO Svelte 6: remove input.value check and set to empty string?
  i(l) == null && e.value) && (u(t(e) ? o(e.value) : e.value), v !== null && s.add(v)), k(() => {
    var r = l();
    if (e === document.activeElement) {
      var a = (
        /** @type {Batch} */
        v
      );
      if (s.has(a))
        return;
    }
    t(e) && r === o(e.value) || e.type === "date" && !r && !e.value || r !== e.value && (e.value = r ?? "");
  });
}
function t(e) {
  var l = e.type;
  return l === "number" || l === "range";
}
function o(e) {
  return e === "" ? null : +e;
}
export {
  h as b
};
//# sourceMappingURL=input-BnNaXS4t.js.map
