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