UNPKG

potentio

Version:

Unstyled & accessible knob primitive for React and Vue

1,035 lines (1,031 loc) 32.1 kB
import Ve, { forwardRef as ie } from "react"; import { useDrag as Sr } from "@use-gesture/react"; import xr from "merge-props"; import { watch as Ye, onUnmounted as We, unref as ae, defineComponent as se, ref as Dr, computed as ne, openBlock as ue, createElementBlock as le, mergeProps as ce, renderSlot as fe } from "vue"; function F(o, t, u) { return Math.max(t, Math.min(u, o)); } function kr(o) { return F(o, 0, 1); } function jr(o, t, u) { return (o - t) / (u - t); } function Fr(o, t, u) { return o * (u - t) + t; } function Ue({ valueRaw: o, valueMin: t, valueMax: u, dragSensitivity: v, deltaX: c, deltaY: p, mapTo01: m, mapFrom01: E }) { let a = 0; a += c * v, a += p * -v; const y = m(o, t, u), h = kr(y + a); return F( E(h, t, u), t, u ); } function Me({ valueRaw: o, valueMin: t, valueMax: u, step: v, stepLarger: c, keyCode: p }) { switch (p) { case "ArrowUp": case "ArrowRight": return F(o + v, t, u); case "ArrowDown": case "ArrowLeft": return F(o - v, t, u); case "PageUp": return F(o + c, t, u); case "PageDown": return F(o - c, t, u); case "Home": return t; case "End": return u; default: return null; } } function He(o, t) { return o ? o === "horizontal" ? "x" : "y" : t === "xy" ? void 0 : t; } function Ne(o, t) { if (o) return o; if (t !== "xy") return t === "x" ? "horizontal" : "vertical"; } const P = { axis: "y", includeIntoTabOrder: !1, mapTo01: jr, mapFrom01: Fr }; var oe = { exports: {} }, U = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ke; function Ir() { if (Ke) return U; Ke = 1; var o = Ve, t = Symbol.for("react.element"), u = Symbol.for("react.fragment"), v = Object.prototype.hasOwnProperty, c = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 }; function m(E, a, y) { var h, O = {}, _ = null, k = null; y !== void 0 && (_ = "" + y), a.key !== void 0 && (_ = "" + a.key), a.ref !== void 0 && (k = a.ref); for (h in a) v.call(a, h) && !p.hasOwnProperty(h) && (O[h] = a[h]); if (E && E.defaultProps) for (h in a = E.defaultProps, a) O[h] === void 0 && (O[h] = a[h]); return { $$typeof: t, type: E, key: _, ref: k, props: O, _owner: c.current }; } return U.Fragment = u, U.jsx = m, U.jsxs = m, U; } var M = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var $e; function Ar() { return $e || ($e = 1, process.env.NODE_ENV !== "production" && function() { var o = Ve, t = Symbol.for("react.element"), u = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), c = Symbol.for("react.strict_mode"), p = Symbol.for("react.profiler"), m = Symbol.for("react.provider"), E = Symbol.for("react.context"), a = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), O = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), k = Symbol.for("react.offscreen"), i = Symbol.iterator, w = "@@iterator"; function L(e) { if (e === null || typeof e != "object") return null; var r = i && e[i] || e[w]; return typeof r == "function" ? r : null; } var C = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function T(e) { { for (var r = arguments.length, n = new Array(r > 1 ? r - 1 : 0), s = 1; s < r; s++) n[s - 1] = arguments[s]; Xe("error", e, n); } } function Xe(e, r, n) { { var s = C.ReactDebugCurrentFrame, d = s.getStackAddendum(); d !== "" && (r += "%s", n = n.concat([d])); var b = n.map(function(f) { return String(f); }); b.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, b); } } var Je = !1, qe = !1, ze = !1, Ge = !1, Ze = !1, ve; ve = Symbol.for("react.module.reference"); function Qe(e) { return !!(typeof e == "string" || typeof e == "function" || e === v || e === p || Ze || e === c || e === y || e === h || Ge || e === k || Je || qe || ze || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === O || e.$$typeof === m || e.$$typeof === E || e.$$typeof === a || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === ve || e.getModuleId !== void 0)); } function er(e, r, n) { var s = e.displayName; if (s) return s; var d = r.displayName || r.name || ""; return d !== "" ? n + "(" + d + ")" : n; } function pe(e) { return e.displayName || "Context"; } function j(e) { if (e == null) return null; if (typeof e.tag == "number" && T("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case v: return "Fragment"; case u: return "Portal"; case p: return "Profiler"; case c: return "StrictMode"; case y: return "Suspense"; case h: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case E: var r = e; return pe(r) + ".Consumer"; case m: var n = e; return pe(n._context) + ".Provider"; case a: return er(e, e.render, "ForwardRef"); case O: var s = e.displayName || null; return s !== null ? s : j(e.type) || "Memo"; case _: { var d = e, b = d._payload, f = d._init; try { return j(f(b)); } catch { return null; } } } return null; } var I = Object.assign, V = 0, me, be, ye, he, ge, Re, Ee; function we() { } we.__reactDisabledLog = !0; function rr() { { if (V === 0) { me = console.log, be = console.info, ye = console.warn, he = console.error, ge = console.group, Re = console.groupCollapsed, Ee = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: we, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } V++; } } function tr() { { if (V--, V === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: I({}, e, { value: me }), info: I({}, e, { value: be }), warn: I({}, e, { value: ye }), error: I({}, e, { value: he }), group: I({}, e, { value: ge }), groupCollapsed: I({}, e, { value: Re }), groupEnd: I({}, e, { value: Ee }) }); } V < 0 && T("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var J = C.ReactCurrentDispatcher, q; function H(e, r, n) { { if (q === void 0) try { throw Error(); } catch (d) { var s = d.stack.trim().match(/\n( *(at )?)/); q = s && s[1] || ""; } return ` ` + q + e; } } var z = !1, N; { var nr = typeof WeakMap == "function" ? WeakMap : Map; N = new nr(); } function _e(e, r) { if (!e || z) return ""; { var n = N.get(e); if (n !== void 0) return n; } var s; z = !0; var d = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var b; b = J.current, J.current = null, rr(); try { if (r) { var f = function() { throw Error(); }; if (Object.defineProperty(f.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(f, []); } catch (x) { s = x; } Reflect.construct(e, [], f); } else { try { f.call(); } catch (x) { s = x; } e.call(f.prototype); } } else { try { throw Error(); } catch (x) { s = x; } e(); } } catch (x) { if (x && s && typeof x.stack == "string") { for (var l = x.stack.split(` `), S = s.stack.split(` `), g = l.length - 1, R = S.length - 1; g >= 1 && R >= 0 && l[g] !== S[R]; ) R--; for (; g >= 1 && R >= 0; g--, R--) if (l[g] !== S[R]) { if (g !== 1 || R !== 1) do if (g--, R--, R < 0 || l[g] !== S[R]) { var D = ` ` + l[g].replace(" at new ", " at "); return e.displayName && D.includes("<anonymous>") && (D = D.replace("<anonymous>", e.displayName)), typeof e == "function" && N.set(e, D), D; } while (g >= 1 && R >= 0); break; } } } finally { z = !1, J.current = b, tr(), Error.prepareStackTrace = d; } var $ = e ? e.displayName || e.name : "", A = $ ? H($) : ""; return typeof e == "function" && N.set(e, A), A; } function ar(e, r, n) { return _e(e, !1); } function or(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function B(e, r, n) { if (e == null) return ""; if (typeof e == "function") return _e(e, or(e)); if (typeof e == "string") return H(e); switch (e) { case y: return H("Suspense"); case h: return H("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case a: return ar(e.render); case O: return B(e.type, r, n); case _: { var s = e, d = s._payload, b = s._init; try { return B(b(d), r, n); } catch { } } } return ""; } var Y = Object.prototype.hasOwnProperty, Te = {}, Pe = C.ReactDebugCurrentFrame; function X(e) { if (e) { var r = e._owner, n = B(e.type, e._source, r ? r.type : null); Pe.setExtraStackFrame(n); } else Pe.setExtraStackFrame(null); } function ir(e, r, n, s, d) { { var b = Function.call.bind(Y); for (var f in e) if (b(e, f)) { var l = void 0; try { if (typeof e[f] != "function") { var S = Error((s || "React class") + ": " + n + " type `" + f + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[f] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw S.name = "Invariant Violation", S; } l = e[f](r, f, s, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (g) { l = g; } l && !(l instanceof Error) && (X(d), T("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", s || "React class", n, f, typeof l), X(null)), l instanceof Error && !(l.message in Te) && (Te[l.message] = !0, X(d), T("Failed %s type: %s", n, l.message), X(null)); } } } var sr = Array.isArray; function G(e) { return sr(e); } function ur(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, n = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return n; } } function lr(e) { try { return Oe(e), !1; } catch { return !0; } } function Oe(e) { return "" + e; } function Ce(e) { if (lr(e)) return T("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ur(e)), Oe(e); } var W = C.ReactCurrentOwner, cr = { key: !0, ref: !0, __self: !0, __source: !0 }, Se, xe, Z; Z = {}; function fr(e) { if (Y.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function dr(e) { if (Y.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function vr(e, r) { if (typeof e.ref == "string" && W.current && r && W.current.stateNode !== r) { var n = j(W.current.type); Z[n] || (T('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', j(W.current.type), e.ref), Z[n] = !0); } } function pr(e, r) { { var n = function() { Se || (Se = !0, T("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; n.isReactWarning = !0, Object.defineProperty(e, "key", { get: n, configurable: !0 }); } } function mr(e, r) { { var n = function() { xe || (xe = !0, T("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; n.isReactWarning = !0, Object.defineProperty(e, "ref", { get: n, configurable: !0 }); } } var br = function(e, r, n, s, d, b, f) { var l = { // This tag allows us to uniquely identify this as a React Element $$typeof: t, // Built-in properties that belong on the element type: e, key: r, ref: n, props: f, // Record the component responsible for creating this element. _owner: b }; return l._store = {}, Object.defineProperty(l._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(l, "_self", { configurable: !1, enumerable: !1, writable: !1, value: s }), Object.defineProperty(l, "_source", { configurable: !1, enumerable: !1, writable: !1, value: d }), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l; }; function yr(e, r, n, s, d) { { var b, f = {}, l = null, S = null; n !== void 0 && (Ce(n), l = "" + n), dr(r) && (Ce(r.key), l = "" + r.key), fr(r) && (S = r.ref, vr(r, d)); for (b in r) Y.call(r, b) && !cr.hasOwnProperty(b) && (f[b] = r[b]); if (e && e.defaultProps) { var g = e.defaultProps; for (b in g) f[b] === void 0 && (f[b] = g[b]); } if (l || S) { var R = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; l && pr(f, R), S && mr(f, R); } return br(e, l, S, d, s, W.current, f); } } var Q = C.ReactCurrentOwner, De = C.ReactDebugCurrentFrame; function K(e) { if (e) { var r = e._owner, n = B(e.type, e._source, r ? r.type : null); De.setExtraStackFrame(n); } else De.setExtraStackFrame(null); } var ee; ee = !1; function re(e) { return typeof e == "object" && e !== null && e.$$typeof === t; } function ke() { { if (Q.current) { var e = j(Q.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function hr(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), n = e.lineNumber; return ` Check your code at ` + r + ":" + n + "."; } return ""; } } var je = {}; function gr(e) { { var r = ke(); if (!r) { var n = typeof e == "string" ? e : e.displayName || e.name; n && (r = ` Check the top-level render call using <` + n + ">."); } return r; } } function Fe(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var n = gr(r); if (je[n]) return; je[n] = !0; var s = ""; e && e._owner && e._owner !== Q.current && (s = " It was passed a child from " + j(e._owner.type) + "."), K(e), T('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, s), K(null); } } function Ie(e, r) { { if (typeof e != "object") return; if (G(e)) for (var n = 0; n < e.length; n++) { var s = e[n]; re(s) && Fe(s, r); } else if (re(e)) e._store && (e._store.validated = !0); else if (e) { var d = L(e); if (typeof d == "function" && d !== e.entries) for (var b = d.call(e), f; !(f = b.next()).done; ) re(f.value) && Fe(f.value, r); } } } function Rr(e) { { var r = e.type; if (r == null || typeof r == "string") return; var n; if (typeof r == "function") n = r.propTypes; else if (typeof r == "object" && (r.$$typeof === a || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === O)) n = r.propTypes; else return; if (n) { var s = j(r); ir(n, e.props, "prop", s, e); } else if (r.PropTypes !== void 0 && !ee) { ee = !0; var d = j(r); T("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", d || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && T("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function Er(e) { { for (var r = Object.keys(e.props), n = 0; n < r.length; n++) { var s = r[n]; if (s !== "children" && s !== "key") { K(e), T("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", s), K(null); break; } } e.ref !== null && (K(e), T("Invalid attribute `ref` supplied to `React.Fragment`."), K(null)); } } var Ae = {}; function Le(e, r, n, s, d, b) { { var f = Qe(e); if (!f) { var l = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (l += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var S = hr(d); S ? l += S : l += ke(); var g; e === null ? g = "null" : G(e) ? g = "array" : e !== void 0 && e.$$typeof === t ? (g = "<" + (j(e.type) || "Unknown") + " />", l = " Did you accidentally export a JSX literal instead of a component?") : g = typeof e, T("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", g, l); } var R = yr(e, r, n, d, b); if (R == null) return R; if (f) { var D = r.children; if (D !== void 0) if (s) if (G(D)) { for (var $ = 0; $ < D.length; $++) Ie(D[$], e); Object.freeze && Object.freeze(D); } else T("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else Ie(D, e); } if (Y.call(r, "key")) { var A = j(e), x = Object.keys(r).filter(function(Cr) { return Cr !== "key"; }), te = x.length > 0 ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!Ae[A + te]) { var Or = x.length > 0 ? "{" + x.join(": ..., ") + ": ...}" : "{}"; T(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, te, A, Or, A), Ae[A + te] = !0; } } return e === v ? Er(R) : Rr(R), R; } } function wr(e, r, n) { return Le(e, r, n, !0); } function _r(e, r, n) { return Le(e, r, n, !1); } var Tr = _r, Pr = wr; M.Fragment = v, M.jsx = Tr, M.jsxs = Pr; }()), M; } process.env.NODE_ENV === "production" ? oe.exports = Ir() : oe.exports = Ar(); var de = oe.exports; const Be = ie( ({ valueRaw: o, valueMin: t, valueMax: u, dragSensitivity: v, valueRawRoundFn: c, valueRawDisplayFn: p, onValueRawChange: m, orientation: E, axis: a = P.axis, includeIntoTabOrder: y = P.includeIntoTabOrder, mapTo01: h = P.mapTo01, mapFrom01: O = P.mapFrom01, disabled: _ = !1, ...k }, i) => { const w = c(o), L = Sr( ({ delta: C }) => { if (_) return; const T = Ue({ valueRaw: o, valueMin: t, valueMax: u, dragSensitivity: v, deltaX: C[0], deltaY: C[1], mapTo01: h, mapFrom01: O }); m(T); }, { enabled: !_, pointer: { // Disabling default keyboard events provided by @use-gesture: // https://use-gesture.netlify.app/docs/options/#pointerkeys keys: !1 }, axis: He(E, a) } ); return /* @__PURE__ */ de.jsx( "div", { ref: i, role: "slider", "aria-valuenow": w, "aria-valuemin": t, "aria-valuemax": u, "aria-orientation": Ne(E, a), "aria-valuetext": p(o), "aria-disabled": _ ? "true" : void 0, "data-disabled": _ ? "" : void 0, tabIndex: y ? 0 : -1, ...xr( L(), { style: { touchAction: "none", // It's recommended to disable "touch-action" for use-gesture: https://use-gesture.netlify.app/docs/extras/#touch-action userSelect: "none", WebkitUserSelect: "none" }, onPointerDown(C) { _ || C.currentTarget.focus(); } }, k ) } ); } ); Be.displayName = "KnobHeadless"; Be.defaultProps = { axis: P.axis, includeIntoTabOrder: P.includeIntoTabOrder, mapTo01: P.mapTo01, mapFrom01: P.mapFrom01 }; const Lr = ie((o, t) => /* @__PURE__ */ de.jsx("label", { ref: t, ...o })); Lr.displayName = "KnobHeadlessLabel"; const Kr = ie((o, t) => /* @__PURE__ */ de.jsx("output", { ref: t, ...o })); Kr.displayName = "KnobHeadlessOutput"; const Jr = ({ valueRaw: o, valueMin: t, valueMax: u, step: v, stepLarger: c, onValueRawChange: p, noDefaultPrevention: m = !1 }) => ({ onKeyDown: (a) => { const y = Me({ valueRaw: o, valueMin: t, valueMax: u, step: v, stepLarger: c, keyCode: a.code }); y !== null && (p(y, a), $r({ event: a, noDefaultPrevention: m })); } }), $r = ({ event: o, noDefaultPrevention: t }) => { t || o.preventDefault(); }; function Vr(o, t, u = {}) { let v = 0, c = 0, p = !1, m = null; const E = (i) => { if (m !== null) return; p = !0, m = i.pointerId, v = i.clientX, c = i.clientY, i.currentTarget.setPointerCapture(i.pointerId); }, a = (i) => { if (!p || i.pointerId !== m) return; const w = i.clientX - v, L = i.clientY - c; let C; u.axis === "x" ? C = [w, 0] : u.axis === "y" ? C = [0, L] : C = [w, L], t({ delta: C }), v = i.clientX, c = i.clientY; }, y = (i) => { if (i.pointerId !== m) return; p = !1, m = null; const w = i.currentTarget; w.hasPointerCapture(i.pointerId) && w.releasePointerCapture(i.pointerId); }, h = (i) => { if (i.pointerId === m) { p = !1, m = null; const w = i.currentTarget; w.hasPointerCapture(i.pointerId) && w.releasePointerCapture(i.pointerId); } }, O = (i) => { if (i.pointerId === m && p) { p = !1, m = null; const w = ae(o); w && w.hasPointerCapture(i.pointerId) && w.releasePointerCapture(i.pointerId); } }, _ = (i) => { p && i.pointerId === m && a(i); }, k = () => { const i = ae(o); i && (i.removeEventListener("pointerdown", E), i.removeEventListener("pointermove", a), i.removeEventListener("pointerup", y), i.removeEventListener("pointercancel", h), window.removeEventListener("pointerup", O), window.removeEventListener("pointermove", _), p = !1, m = null); }; Ye(o, (i, w) => { w && k(), i && (i.addEventListener("pointerdown", E), i.addEventListener("pointermove", a), i.addEventListener("pointerup", y), i.addEventListener("pointercancel", h), window.addEventListener("pointerup", O), window.addEventListener("pointermove", _)); }, { immediate: !0 }), We(k); } function Yr(o, t) { const u = (c) => { c.preventDefault(), t({ deltaY: c.deltaY, deltaX: c.deltaX, event: c }); }, v = () => { const c = ae(o); c && c.removeEventListener("wheel", u); }; Ye(o, (c, p) => { p && v(), c && c.addEventListener("wheel", u, { passive: !1 }); }, { immediate: !0 }), We(v); } const Wr = ["aria-valuenow", "aria-valuemin", "aria-valuemax", "aria-orientation", "aria-valuetext", "aria-label", "aria-labelledby", "aria-disabled", "data-disabled", "tabindex"], qr = /* @__PURE__ */ se({ __name: "KnobHeadless", props: { wheelSensitivity: { default: 0.01 }, valueRaw: {}, valueMin: {}, valueMax: {}, dragSensitivity: {}, valueRawRoundFn: {}, valueRawDisplayFn: {}, onValueRawChange: {}, orientation: {}, axis: { default: P.axis }, includeIntoTabOrder: { type: Boolean, default: P.includeIntoTabOrder }, mapTo01: { type: Function, default: P.mapTo01 }, mapFrom01: { type: Function, default: P.mapFrom01 }, disabled: { type: Boolean }, "aria-label": {}, "aria-labelledby": {} }, setup(o) { const t = o, u = Dr(), v = ne(() => t.valueRawRoundFn(t.valueRaw)), c = ne(() => He(t.orientation, t.axis || P.axis)), p = ne(() => Ne(t.orientation, t.axis || P.axis)); Vr( u, ({ delta: a }) => { if (t.disabled) return; const y = Ue({ valueRaw: t.valueRaw, valueMin: t.valueMin, valueMax: t.valueMax, dragSensitivity: t.dragSensitivity, deltaX: a[0], deltaY: a[1], mapTo01: t.mapTo01 || P.mapTo01, mapFrom01: t.mapFrom01 || P.mapFrom01 }); t.onValueRawChange(y); }, { axis: c.value } ), Yr(u, ({ deltaY: a, deltaX: y }) => { if (t.disabled) return; let h = 0; c.value === "x" ? h = -y : c.value === "y" ? h = -a : h = Math.abs(a) > Math.abs(y) ? -a : -y; const O = h * t.wheelSensitivity, _ = (t.mapTo01 || P.mapTo01)( t.valueRaw, t.valueMin, t.valueMax ), k = F(_ + O, 0, 1), i = F( (t.mapFrom01 || P.mapFrom01)( k, t.valueMin, t.valueMax ), t.valueMin, t.valueMax ); t.onValueRawChange(i); }); const m = (a) => { t.disabled || a.currentTarget.focus(); }, E = (a) => { a.preventDefault(); }; return (a, y) => (ue(), le("div", ce({ ref_key: "knobRef", ref: u, role: "slider", "aria-valuenow": v.value, "aria-valuemin": a.valueMin, "aria-valuemax": a.valueMax, "aria-orientation": p.value, "aria-valuetext": a.valueRawDisplayFn(a.valueRaw), "aria-label": a.ariaLabel, "aria-labelledby": a.ariaLabelledby, "aria-disabled": a.disabled ? "true" : void 0, "data-disabled": a.disabled ? "" : void 0, tabindex: a.includeIntoTabOrder ? 0 : -1, style: { touchAction: "none", userSelect: "none", WebkitUserSelect: "none" }, onPointerdown: m, onKeydown: E }, a.$attrs), [ fe(a.$slots, "default") ], 16, Wr)); } }), Ur = ["id"], zr = /* @__PURE__ */ se({ __name: "KnobHeadlessLabel", props: { id: {} }, setup(o) { return (t, u) => (ue(), le("label", ce({ id: t.id }, t.$attrs), [ fe(t.$slots, "default") ], 16, Ur)); } }), Mr = ["for"], Gr = /* @__PURE__ */ se({ __name: "KnobHeadlessOutput", props: { htmlFor: {} }, setup(o) { return (t, u) => (ue(), le("output", ce({ for: t.htmlFor }, t.$attrs), [ fe(t.$slots, "default") ], 16, Mr)); } }); function Zr({ valueRaw: o, valueMin: t, valueMax: u, step: v, stepLarger: c, onValueRawChange: p, noDefaultPrevention: m = !1 }) { return { onKeyDown: (a) => { const y = Me({ valueRaw: o, valueMin: t, valueMax: u, step: v, stepLarger: c, keyCode: a.code }); y !== null && (p(y, a), m || a.preventDefault()); } }; } export { P as KNOB_DEFAULTS, Be as ReactKnobHeadless, Lr as ReactKnobHeadlessLabel, Kr as ReactKnobHeadlessOutput, qr as VueKnobHeadless, zr as VueKnobHeadlessLabel, Gr as VueKnobHeadlessOutput, Ue as calculateDragValue, Me as calculateKeyboardValue, Ne as getAriaOrientation, He as getDragAxis, Jr as useReactKnobKeyboardControls, Zr as useVueKnobKeyboardControls }; //# sourceMappingURL=potentio.es.js.map