UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

40 lines (39 loc) 1.07 kB
function d(e, t) { const { current: i, min: a, max: r, step: n = 1, coarseStep: o = n * 10 } = t, s = e.shiftKey ? o : n; switch (e.key) { case "ArrowRight": case "ArrowUp": return Math.min(r, i + s); case "ArrowLeft": case "ArrowDown": return Math.max(a, i - s); case "Home": return a; case "End": return r; default: return; } } function l(e) { return e.key === "Enter" || e.key === " " || e.key === "Spacebar"; } function y(e, t, i) { const { disabled: a, required: r, isEmpty: n, message: o = "Please fill out this field.", anchor: s, ariaTarget: u = e } = i; r ? u.setAttribute("aria-required", "true") : u.removeAttribute("aria-required"); const c = !a && r && n; c ? u.setAttribute("aria-invalid", "true") : u.removeAttribute("aria-invalid"), t && (c ? t.setValidity?.({ valueMissing: !0 }, o, s) : t.setValidity?.({})); } function f(e) { return e?.checkValidity?.() ?? !0; } function m(e) { return e?.reportValidity?.() ?? !0; } export { y as a, d as i, l as n, m as r, f as t };