function N(n,t,e){return Math.min(e,Math.max(t,n))}function u(n,t){const e=Number(n);return Number.isFinite(e)?e:Number(t)}function b(n,t){if(!n)throw new Error(`Missing Voxis realtime control ${t}.`);if(typeof n=="string"){if(typeof document>"u")throw new Error(`Cannot resolve selector ${n} without a document.`);const e=document.querySelector(n);if(!e)throw new Error(`Could not find element for selector ${n}.`);return e}return n}function k(n,t,e){if(!(t>0))return n;const i=(n-e)/t;return e+Math.round(i)*t}function y(n,t){const e=u(n,t.fallback),i=k(e,t.step,t.min),s=N(i,t.min,t.max);return Number(s.toFixed(t.precision))}function S(n){if(!Number.isFinite(n)||n<=0)return 6;const t=String(n);return t.includes(".")?Math.min(8,t.length-t.indexOf(".")-1):0}function f(n,t,e){const i=String(e);t in n&&(n[t]=i),typeof n.setAttribute=="function"&&n.setAttribute(t,i)}function z({input:n,output:t=null,min:e=0,max:i=1,step:s=.01,fallback:v=e,format:E=r=>String(r),onChange:h=null,listen:w=!0}={}){const r=b(n,"input"),a=t?b(t,"output"):null,o={min:Math.min(u(e,0),u(i,1)),max:Math.max(u(e,0),u(i,1)),step:Math.max(0,u(s,0)),fallback:u(v,e),precision:S(u(s,0))};function m(){f(r,"min",o.min),f(r,"max",o.max),o.step>0&&f(r,"step",o.step)}function d(c){const l=y(c,o);return f(r,"value",l),"value"in r&&(r.value=String(l)),a&&(a.textContent=E(l)),l}function p(){return m(),d(r.value)}function M(c){return m(),d(c)}const x={element:r,output:a,min:o.min,max:o.max,step:o.step,read:p,write:M,lock(){return m(),d(r.value)},get value(){return p()}};if(w&&typeof r.addEventListener=="function"){const c=()=>{const l=p();typeof h=="function"&&h(l,x)};r.addEventListener("input",c),r.addEventListener("change",c)}return x.lock(),x}export{z as createLockedControl};

