@radix-ui/react-slider
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
var e,n,t=require("@radix-ui/react-collection").createCollection,r=require("@radix-ui/react-primitive").Primitive,o=require("@radix-ui/react-utils"),i=o.composeEventHandlers,u=o.createContext,a=o.useComposedRefs,l=o.useControlledState,c=o.useCallbackRef,d=o.useSize,f=require("@radix-ui/utils"),s=f.clamp,v=f.getSelector,m=(e={},n=require("react"),Object.keys(n).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),e);function p(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function h(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?p(Object(t),!0).forEach((function(n){S(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):p(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function S(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function y(){return(y=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function b(e){return function(e){if(Array.isArray(e))return x(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||E(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function w(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(t.push(u.value),!n||t.length!==n);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return t}(e,n)||E(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,n){if(e){if("string"==typeof e)return x(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?x(e,n):void 0}}function x(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var M=["PageUp","PageDown"],O=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],T={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},D=w(t("Slider"),2),R=D[0],P=D[1],j=R((function(e){return m.createElement(m.Fragment,null,e.children)})),A=w(u("SliderContext","Slider"),2),C=A[0],K=A[1],k=m.forwardRef((function(e,n){var t=e.children,r=e.name,o=e.min,i=void 0===o?0:o,u=e.max,c=void 0===u?100:u,d=e.step,f=void 0===d?1:d,v=e.orientation,p=void 0===v?"horizontal":v,h=e.disabled,S=void 0!==h&&h,E=e.minStepsBetweenThumbs,x=void 0===E?0:E,T=e.defaultValue,D=void 0===T?[i]:T,R=e.value,P=e.onValueChange,A=void 0===P?function(){}:P,K=g(e,["children","name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),k=Math.max(f,1),I=m.useRef(null),H=a(n,I),z=m.useRef(new Set),q=m.useRef(0),F="horizontal"===p?L:U,V=w(l({prop:R,defaultProp:D,onChange:A}),2),B=V[0],N=void 0===B?[]:B,G=V[1];function $(e,n){var t=Math.round((e-i)/k)*k+i,r=s(t,[i,c]);return new Promise((function(e){G((function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=Y(t,r,n);return _(o,x*k)?(q.current=o.indexOf(r),e(q.current),o[n]!==t[n]?o:t):(e(q.current),t)}))}))}function J(e){var n;null===(n=b(z.current)[e])||void 0===n||n.focus()}return m.createElement(F,y({},K,{ref:H,min:i,max:c,"aria-disabled":S,"data-disabled":S,onSlideStart:S?void 0:function(e){$(e,function(e,n){if(1===e.length)return 0;var t=e.map((function(e){return Math.abs(e-n)})),r=Math.min.apply(Math,b(t));return t.indexOf(r)}(N,e)).then((function(e){window.setTimeout((function(){return J(e)}),0)}))},onSlideMove:S?void 0:function(e){$(e,q.current).then(J)},onHomeKeyDown:function(){return!S&&$(i,0)},onEndKeyDown:function(){return!S&&$(c,N.length-1)},onStepKeyDown:function(e){var n=e.event,t=e.direction;if(!S){var r=M.includes(n.key)||n.shiftKey&&O.includes(n.key)?10:1,o=q.current;$(N[o]+k*r*t,o)}}}),r&&N.map((function(e,n){return m.createElement(X,{key:n,name:r+(N.length>1?"[]":""),value:e,hidden:!0})})),m.createElement(C.Provider,{value:m.useMemo((function(){return{min:i,max:c,valueIndexToChangeRef:q,thumbs:z.current,values:N,orientation:p}}),[i,c,N,p])},m.createElement(j,null,t)))}));exports.Slider=k,k.displayName="Slider";var I=m.createContext({}),L=m.forwardRef((function(e,n){var t=e.min,r=e.max,o=e.dir,i=e.children,u=e.onSlideStart,l=e.onSlideMove,c=e.onStepKeyDown,d=g(e,["min","max","dir","children","onSlideStart","onSlideMove","onStepKeyDown"]),f=m.useRef(null),s=a(n,f),v=m.useRef(),p=function(e){var n=e.ref,t=e.directionProp,r=w(m.useState("ltr"),2),o=r[0],i=r[1],u=w(m.useState(),2),a=u[0],l=u[1],c=m.useRef(0);return m.useEffect((function(){if(void 0===t){var e=getComputedStyle(n.current);l(e)}}),[t,n]),m.useEffect((function(){function e(){c.current=requestAnimationFrame((function(){var n=null==a?void 0:a.direction;n&&i(n),e()}))}return void 0===t&&e(),function(){return cancelAnimationFrame(c.current)}}),[a,t,i]),t||o}({ref:f,directionProp:o}),b="ltr"===p;function E(e){var n=v.current||f.current.getBoundingClientRect(),o=G([0,n.width],b?[t,r]:[r,t]);return v.current=n,o(e-n.left)}return m.createElement(H,y({},d,{ref:s,style:h(h({},d.style),{},S({},"--radix-slider-thumb-transform","translateX(-50%)")),"data-orientation":"horizontal",onSlideMouseDown:function(e){var n=E(e.clientX);null==u||u(n)},onSlideMouseMove:function(e){var n=E(e.clientX);null==l||l(n)},onSlideMouseUp:function(){return v.current=void 0},onSlideTouchStart:function(e){var n=E(e.targetTouches[0].clientX);null==u||u(n)},onSlideTouchMove:function(e){var n=E(e.targetTouches[0].clientX);null==l||l(n)},onSlideTouchEnd:function(){return v.current=void 0},onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((function(e){var n=T[p].includes(e.key);null==c||c({event:e,direction:n?-1:1})}))}),m.createElement(I.Provider,{value:m.useMemo((function(){return{startEdge:"left",endEdge:"right",size:"width"}}),[])},b?i:m.createElement("span",{style:{flexGrow:1,display:"flex",alignItems:"center",transform:"rotate(180deg)"}},i)))})),U=m.forwardRef((function(e,n){var t=e.min,r=e.max,o=e.children,i=e.onSlideStart,u=e.onSlideMove,l=e.onStepKeyDown,c=g(e,["min","max","children","onSlideStart","onSlideMove","onStepKeyDown"]),d=m.useRef(null),f=a(n,d),s=m.useRef();function v(e){var n=s.current||d.current.getBoundingClientRect(),o=G([0,n.height],[r,t]);return s.current=n,o(e-n.top)}return m.createElement(H,y({},c,{ref:f,style:h(h({},c.style),{},S({},"--radix-slider-thumb-transform","translateY(50%)")),"data-orientation":"vertical",onSlideMouseDown:function(e){var n=v(e.clientY);null==i||i(n)},onSlideMouseMove:function(e){var n=v(e.clientY);null==u||u(n)},onSlideMouseUp:function(){return s.current=void 0},onSlideTouchStart:function(e){var n=v(e.targetTouches[0].clientY);null==i||i(n)},onSlideTouchMove:function(e){var n=v(e.targetTouches[0].clientY);null==u||u(n)},onSlideTouchEnd:function(){return s.current=void 0},onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((function(e){var n=T.ltr.includes(e.key);null==l||l({event:e,direction:n?-1:1})}))}),m.createElement(I.Provider,{value:m.useMemo((function(){return{startEdge:"bottom",endEdge:"top",size:"height"}}),[])},o))})),H=m.forwardRef((function(e,n){var t=e.as,o=void 0===t?"span":t,u=e.selector,a=void 0===u?v("Slider"):u,l=e.onSlideMouseDown,d=e.onSlideMouseMove,f=e.onSlideMouseUp,s=e.onSlideTouchStart,p=e.onSlideTouchMove,h=e.onSlideTouchEnd,S=e.onHomeKeyDown,b=e.onEndKeyDown,w=e.onStepKeyDown,E=g(e,["as","selector","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),x=c(d),T=c(p),D=c((function(){document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",D),f()})),R=c((function(){document.removeEventListener("touchmove",T),document.removeEventListener("touchend",R),h()}));return m.useEffect((function(){return function(){D(),R()}}),[D,R]),m.createElement(r,y({},E,{as:o,selector:a,ref:n,onMouseDown:i(e.onMouseDown,(function(e){0===e.button&&(B(e.target)||l(e),document.addEventListener("mousemove",x),document.addEventListener("mouseup",D))})),onTouchStart:i(e.onTouchStart,(function(e){B(e.target)?e.target.focus():s(e),document.addEventListener("touchmove",T),document.addEventListener("touchend",R),e.preventDefault()})),onKeyDown:i(e.onKeyDown,(function(e){"Home"===e.key?S(e):"End"===e.key?b(e):M.concat(O).includes(e.key)&&(w(e),e.preventDefault())})),onPointerDown:i(e.onPointerDown,(function(e){e.target.setPointerCapture(e.pointerId)})),onPointerUp:i(e.onPointerUp,(function(e){e.target.releasePointerCapture(e.pointerId)}))}))})),z=m.forwardRef((function(e,n){var t=e.as,o=void 0===t?"span":t,i=e.selector,u=void 0===i?v("SliderTrack"):i,a=g(e,["as","selector"]),l=K("SliderTrack");return m.createElement(r,y({},a,{as:o,selector:u,ref:n,"data-orientation":l.orientation}))}));exports.SliderTrack=z,z.displayName="SliderTrack";var q=m.forwardRef((function(e,n){var t,o=e.as,i=void 0===o?"span":o,u=e.selector,l=void 0===u?v("SliderRange"):u,c=g(e,["as","selector"]),d=K("SliderRange"),f=m.useContext(I),s=m.useRef(null),p=a(n,s),w=d.values.length,E=d.values.map((function(e){return N(e,d.min,d.max)})),x=w>1?Math.min.apply(Math,b(E)):0,M=100-Math.max.apply(Math,b(E));return m.createElement(r,y({},c,{as:i,selector:l,ref:p,style:h(h({},e.style),{},(t={},S(t,f.startEdge,x+"%"),S(t,f.endEdge,M+"%"),t)),"data-orientation":d.orientation}))}));exports.SliderRange=q,q.displayName="SliderRange";var F=m.forwardRef((function(e,n){var t=P(),r=t.ref,o=t.index,i=a(n,r),u=K("SliderThumb").values[o];return void 0!==u?m.createElement(V,y({},e,{ref:i,index:o,value:u})):null}));exports.SliderThumb=F;var V=m.forwardRef((function(e,n){var t,o,u,l=e.as,c=void 0===l?"span":l,f=e.selector,s=void 0===f?v("SliderThumb"):f,p=e.index,h=e.value,b=g(e,["as","selector","index","value"]),w=K("SliderThumb"),E=m.useContext(I),x=m.useRef(null),M=a(n,x),O=d(x),T=N(h,w.min,w.max),D=function(e,n){return n>2?"Value ".concat(e+1," of ").concat(n):2===n?["Minimum","Maximum"][e]:void 0}(p,w.values.length),R=null==O?void 0:O[E.size],P=R?(t=T,u=G([0,50],[0,o=R/2]),o-u(t)):0;return m.useEffect((function(){var e=x.current;if(e)return w.thumbs.add(e),function(){w.thumbs.delete(e)}}),[w.thumbs]),m.createElement("span",{style:S({transform:"var(--radix-slider-thumb-transform)",position:"absolute"},E.startEdge,"calc(".concat(T,"% + ").concat(P,"px)"))},m.createElement(r,y({},b,{as:c,selector:s,ref:M,"aria-label":e["aria-label"]||D,"aria-valuemin":w.min,"aria-valuenow":h,"aria-valuemax":w.max,"aria-orientation":w.orientation,"data-orientation":w.orientation,role:"slider",tabIndex:0,onFocus:i(e.onFocus,(function(){w.valueIndexToChangeRef.current=p}))})))}));F.displayName="SliderThumb";var X=function(e){var n=e.value,t=g(e,["value"]),r=m.useRef(null);return m.useEffect((function(){var e=r.current,t=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(t,"value").set;if(o){var i=new Event("input",{bubbles:!0});o.call(e,n),e.dispatchEvent(i)}}),[n]),m.createElement("input",y({hidden:!0},t,{ref:r}))};function Y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,t=arguments.length>2?arguments[2]:void 0,r=b(e);return r[t]=n,r.sort((function(e,n){return e-n}))}function B(e){var n="data-".concat(v("SliderThumb"));return""===e.getAttribute(n)}function N(e,n,t){return 100/(t-n)*(e-n)}function _(e,n){if(n>0){var t=function(e){return e.slice(0,-1).map((function(n,t){return e[t+1]-n}))}(e);return Math.min.apply(Math,b(t))>=n}return!0}function G(e,n){return function(t){if(e[0]===e[1]||n[0]===n[1])return n[0];var r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}var $=k;exports.Root=$;var J=z;exports.Track=J;var Q=q;exports.Range=Q;var W=F;exports.Thumb=W; | ||
var e,n,t=require("@radix-ui/react-collection").createCollection,r=require("@radix-ui/react-primitive").Primitive,o=require("@radix-ui/react-utils"),i=o.composeEventHandlers,u=o.createContext,a=o.useComposedRefs,l=o.useControlledState,c=o.useCallbackRef,d=o.useSize,f=require("@radix-ui/utils"),s=f.clamp,v=f.getSelector,m=(e={},n=require("react"),Object.keys(n).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),e);function p(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function h(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?p(Object(t),!0).forEach((function(n){S(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):p(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function S(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function y(){return(y=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function b(e){return function(e){if(Array.isArray(e))return x(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||E(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function w(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(t.push(u.value),!n||t.length!==n);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return t}(e,n)||E(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,n){if(e){if("string"==typeof e)return x(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?x(e,n):void 0}}function x(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var M=["PageUp","PageDown"],O=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],T={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},D=w(t("Slider"),2),R=D[0],P=D[1],j=R((function(e){return m.createElement(m.Fragment,null,e.children)})),A=w(u("SliderContext","Slider"),2),C=A[0],K=A[1],k=m.forwardRef((function(e,n){var t=e.name,r=e.min,o=void 0===r?0:r,i=e.max,u=void 0===i?100:i,c=e.step,d=void 0===c?1:c,f=e.orientation,v=void 0===f?"horizontal":f,p=e.disabled,h=void 0!==p&&p,S=e.minStepsBetweenThumbs,E=void 0===S?0:S,x=e.defaultValue,T=void 0===x?[o]:x,D=e.value,R=e.onValueChange,P=void 0===R?function(){}:R,A=g(e,["name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),K=Math.max(d,1),k=m.useRef(null),I=a(n,k),H=m.useRef(new Set),z=m.useRef(0),q="horizontal"===v?L:U,F=w(l({prop:D,defaultProp:T,onChange:P}),2),V=F[0],B=void 0===V?[]:V,N=F[1];function $(e,n){var t=Math.round((e-o)/K)*K+o,r=s(t,[o,u]);return new Promise((function(e){N((function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=Y(t,r,n);return _(o,E*K)?(z.current=o.indexOf(r),e(z.current),o[n]!==t[n]?o:t):(e(z.current),t)}))}))}function G(e){var n;null===(n=b(H.current)[e])||void 0===n||n.focus()}return m.createElement(C.Provider,{value:m.useMemo((function(){return{min:o,max:u,valueIndexToChangeRef:z,thumbs:H.current,values:B,orientation:v}}),[o,u,B,v])},m.createElement(j,null,m.createElement(q,y({},A,{ref:I,min:o,max:u,"aria-disabled":h,"data-disabled":h,onSlideStart:h?void 0:function(e){$(e,function(e,n){if(1===e.length)return 0;var t=e.map((function(e){return Math.abs(e-n)})),r=Math.min.apply(Math,b(t));return t.indexOf(r)}(B,e)).then((function(e){window.setTimeout((function(){return G(e)}),0)}))},onSlideMove:h?void 0:function(e){$(e,z.current).then(G)},onHomeKeyDown:function(){return!h&&$(o,0)},onEndKeyDown:function(){return!h&&$(u,B.length-1)},onStepKeyDown:function(e){var n=e.event,t=e.direction;if(!h){var r=M.includes(n.key)||n.shiftKey&&O.includes(n.key)?10:1,o=z.current;$(B[o]+K*r*t,o)}}})),t&&B.map((function(e,n){return m.createElement(X,{key:n,name:t+(B.length>1?"[]":""),value:e,hidden:!0})}))))}));exports.Slider=k,k.displayName="Slider";var I=m.createContext({}),L=m.forwardRef((function(e,n){var t=e.min,r=e.max,o=e.dir,i=e.onSlideStart,u=e.onSlideMove,l=e.onStepKeyDown,c=g(e,["min","max","dir","onSlideStart","onSlideMove","onStepKeyDown"]),d=m.useRef(null),f=a(n,d),s=m.useRef(),v=function(e){var n=e.ref,t=e.directionProp,r=w(m.useState("ltr"),2),o=r[0],i=r[1],u=w(m.useState(),2),a=u[0],l=u[1],c=m.useRef(0);return m.useEffect((function(){if(void 0===t){var e=getComputedStyle(n.current);l(e)}}),[t,n]),m.useEffect((function(){function e(){c.current=requestAnimationFrame((function(){var n=null==a?void 0:a.direction;n&&i(n),e()}))}return void 0===t&&e(),function(){return cancelAnimationFrame(c.current)}}),[a,t,i]),t||o}({ref:d,directionProp:o}),p="ltr"===v;function b(e){var n=s.current||d.current.getBoundingClientRect(),o=$([0,n.width],p?[t,r]:[r,t]);return s.current=n,o(e-n.left)}return m.createElement(I.Provider,{value:m.useMemo((function(){return{startEdge:p?"left":"right",endEdge:p?"right":"left",direction:p?1:-1,size:"width"}}),[p])},m.createElement(H,y({},c,{ref:f,style:h(h({},c.style),{},S({},"--radix-slider-thumb-transform","translateX(-50%)")),"data-orientation":"horizontal",onSlideMouseDown:function(e){var n=b(e.clientX);null==i||i(n)},onSlideMouseMove:function(e){var n=b(e.clientX);null==u||u(n)},onSlideMouseUp:function(){return s.current=void 0},onSlideTouchStart:function(e){var n=b(e.targetTouches[0].clientX);null==i||i(n)},onSlideTouchMove:function(e){var n=b(e.targetTouches[0].clientX);null==u||u(n)},onSlideTouchEnd:function(){return s.current=void 0},onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((function(e){var n=T[v].includes(e.key);null==l||l({event:e,direction:n?-1:1})}))})))})),U=m.forwardRef((function(e,n){var t=e.min,r=e.max,o=e.onSlideStart,i=e.onSlideMove,u=e.onStepKeyDown,l=g(e,["min","max","onSlideStart","onSlideMove","onStepKeyDown"]),c=m.useRef(null),d=a(n,c),f=m.useRef();function s(e){var n=f.current||c.current.getBoundingClientRect(),o=$([0,n.height],[r,t]);return f.current=n,o(e-n.top)}return m.createElement(I.Provider,{value:m.useMemo((function(){return{startEdge:"bottom",endEdge:"top",size:"height",direction:1}}),[])},m.createElement(H,y({},l,{ref:d,style:h(h({},l.style),{},S({},"--radix-slider-thumb-transform","translateY(50%)")),"data-orientation":"vertical",onSlideMouseDown:function(e){var n=s(e.clientY);null==o||o(n)},onSlideMouseMove:function(e){var n=s(e.clientY);null==i||i(n)},onSlideMouseUp:function(){return f.current=void 0},onSlideTouchStart:function(e){var n=s(e.targetTouches[0].clientY);null==o||o(n)},onSlideTouchMove:function(e){var n=s(e.targetTouches[0].clientY);null==i||i(n)},onSlideTouchEnd:function(){return f.current=void 0},onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((function(e){var n=T.ltr.includes(e.key);null==u||u({event:e,direction:n?-1:1})}))})))})),H=m.forwardRef((function(e,n){var t=e.as,o=void 0===t?"span":t,u=e.selector,a=void 0===u?v("Slider"):u,l=e.onSlideMouseDown,d=e.onSlideMouseMove,f=e.onSlideMouseUp,s=e.onSlideTouchStart,p=e.onSlideTouchMove,h=e.onSlideTouchEnd,S=e.onHomeKeyDown,b=e.onEndKeyDown,w=e.onStepKeyDown,E=g(e,["as","selector","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),x=c(d),T=c(p),D=c((function(){document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",D),f()})),R=c((function(){document.removeEventListener("touchmove",T),document.removeEventListener("touchend",R),h()}));return m.useEffect((function(){return function(){D(),R()}}),[D,R]),m.createElement(r,y({},E,{as:o,selector:a,ref:n,onMouseDown:i(e.onMouseDown,(function(e){0===e.button&&(B(e.target)||l(e),document.addEventListener("mousemove",x),document.addEventListener("mouseup",D))})),onTouchStart:i(e.onTouchStart,(function(e){B(e.target)?e.target.focus():s(e),document.addEventListener("touchmove",T),document.addEventListener("touchend",R),e.preventDefault()})),onKeyDown:i(e.onKeyDown,(function(e){"Home"===e.key?S(e):"End"===e.key?b(e):M.concat(O).includes(e.key)&&(w(e),e.preventDefault())})),onPointerDown:i(e.onPointerDown,(function(e){e.target.setPointerCapture(e.pointerId)})),onPointerUp:i(e.onPointerUp,(function(e){e.target.releasePointerCapture(e.pointerId)}))}))})),z=m.forwardRef((function(e,n){var t=e.as,o=void 0===t?"span":t,i=e.selector,u=void 0===i?v("SliderTrack"):i,a=g(e,["as","selector"]),l=K("SliderTrack");return m.createElement(r,y({},a,{as:o,selector:u,ref:n,"data-orientation":l.orientation}))}));exports.SliderTrack=z,z.displayName="SliderTrack";var q=m.forwardRef((function(e,n){var t,o=e.as,i=void 0===o?"span":o,u=e.selector,l=void 0===u?v("SliderRange"):u,c=g(e,["as","selector"]),d=K("SliderRange"),f=m.useContext(I),s=m.useRef(null),p=a(n,s),w=d.values.length,E=d.values.map((function(e){return N(e,d.min,d.max)})),x=w>1?Math.min.apply(Math,b(E)):0,M=100-Math.max.apply(Math,b(E));return m.createElement(r,y({},c,{as:i,selector:l,ref:p,style:h(h({},e.style),{},(t={},S(t,f.startEdge,x+"%"),S(t,f.endEdge,M+"%"),t)),"data-orientation":d.orientation}))}));exports.SliderRange=q,q.displayName="SliderRange";var F=m.forwardRef((function(e,n){var t=P(),r=t.ref,o=t.index,i=a(n,r),u=K("SliderThumb").values[o];return void 0!==u?m.createElement(V,y({},e,{ref:i,index:o,value:u})):null}));exports.SliderThumb=F;var V=m.forwardRef((function(e,n){var t,o,u,l,c,f=e.as,s=void 0===f?"span":f,p=e.selector,h=void 0===p?v("SliderThumb"):p,b=e.index,w=e.value,E=g(e,["as","selector","index","value"]),x=K("SliderThumb"),M=m.useContext(I),O=m.useRef(null),T=a(n,O),D=d(O),R=N(w,x.min,x.max),P=function(e,n){return n>2?"Value ".concat(e+1," of ").concat(n):2===n?["Minimum","Maximum"][e]:void 0}(b,x.values.length),j=null==D?void 0:D[M.size],A=j?(t=j,o=R,u=M.direction,c=$([0,50],[0,l=t/2]),(l-c(o)*u)*u):0;return m.useEffect((function(){var e=O.current;if(e)return x.thumbs.add(e),function(){x.thumbs.delete(e)}}),[x.thumbs]),m.createElement("span",{style:S({transform:"var(--radix-slider-thumb-transform)",position:"absolute"},M.startEdge,"calc(".concat(R,"% + ").concat(A,"px)"))},m.createElement(r,y({},E,{as:s,selector:h,ref:T,"aria-label":e["aria-label"]||P,"aria-valuemin":x.min,"aria-valuenow":w,"aria-valuemax":x.max,"aria-orientation":x.orientation,"data-orientation":x.orientation,role:"slider",tabIndex:0,onFocus:i(e.onFocus,(function(){x.valueIndexToChangeRef.current=b}))})))}));F.displayName="SliderThumb";var X=function(e){var n=e.value,t=g(e,["value"]),r=m.useRef(null);return m.useEffect((function(){var e=r.current,t=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(t,"value").set;if(o){var i=new Event("input",{bubbles:!0});o.call(e,n),e.dispatchEvent(i)}}),[n]),m.createElement("input",y({hidden:!0},t,{ref:r}))};function Y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,t=arguments.length>2?arguments[2]:void 0,r=b(e);return r[t]=n,r.sort((function(e,n){return e-n}))}function B(e){var n="data-".concat(v("SliderThumb"));return""===e.getAttribute(n)}function N(e,n,t){return 100/(t-n)*(e-n)}function _(e,n){if(n>0){var t=function(e){return e.slice(0,-1).map((function(n,t){return e[t+1]-n}))}(e);return Math.min.apply(Math,b(t))>=n}return!0}function $(e,n){return function(t){if(e[0]===e[1]||n[0]===n[1])return n[0];var r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}var G=k;exports.Root=G;var J=z;exports.Track=J;var Q=q;exports.Range=Q;var W=F;exports.Thumb=W; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{createCollection as e}from"@radix-ui/react-collection";import{Primitive as t}from"@radix-ui/react-primitive";import{composeEventHandlers as n,createContext as r,useComposedRefs as o,useControlledState as i,useCallbackRef as a,useSize as u}from"@radix-ui/react-utils";import{clamp as l,getSelector as c}from"@radix-ui/utils";import*as s from"react";function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function m(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(){return(p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}const v=["PageUp","PageDown"],S=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],w={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[g,y]=e("Slider"),b=g((e=>s.createElement(s.Fragment,null,e.children))),E="Slider",x="span",[M,D]=r("SliderContext",E);export const Slider=s.forwardRef(((e,t)=>{const{children:n,name:r,min:a=0,max:u=100,step:c=1,orientation:d="horizontal",disabled:m=!1,minStepsBetweenThumbs:f=0,defaultValue:w=[a],value:g,onValueChange:y=(()=>{})}=e,E=h(e,["children","name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),x=Math.max(c,1),D=s.useRef(null),T=o(t,D),P=s.useRef(new Set),j=s.useRef(0),K="horizontal"===d?O:R,[k=[],C]=i({prop:g,defaultProp:w,onChange:y});function A(e,t){const n=Math.round((e-a)/x)*x+a,r=l(n,[a,u]);return new Promise((e=>{C(((n=[])=>{const o=function(e=[],t,n){const r=[...e];return r[n]=t,r.sort(((e,t)=>e-t))}(n,r,t);return function(e,t){if(t>0){const n=function(e){return e.slice(0,-1).map(((t,n)=>e[n+1]-t))}(e);return Math.min(...n)>=t}return!0}(o,f*x)?(j.current=o.indexOf(r),e(j.current),o[t]!==n[t]?o:n):(e(j.current),n)}))}))}function L(e){var t;null===(t=[...P.current][e])||void 0===t||t.focus()}return s.createElement(K,p({},E,{ref:T,min:a,max:u,"aria-disabled":m,"data-disabled":m,onSlideStart:m?void 0:function(e){A(e,function(e,t){if(1===e.length)return 0;const n=e.map((e=>Math.abs(e-t))),r=Math.min(...n);return n.indexOf(r)}(k,e)).then((e=>{window.setTimeout((()=>L(e)),0)}))},onSlideMove:m?void 0:function(e){A(e,j.current).then(L)},onHomeKeyDown:()=>!m&&A(a,0),onEndKeyDown:()=>!m&&A(u,k.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!m){const n=v.includes(e.key)||e.shiftKey&&S.includes(e.key)?10:1,r=j.current;A(k[r]+x*n*t,r)}}}),r&&k.map(((e,t)=>s.createElement(I,{key:t,name:r+(k.length>1?"[]":""),value:e,hidden:!0}))),s.createElement(M.Provider,{value:s.useMemo((()=>({min:a,max:u,valueIndexToChangeRef:j,thumbs:P.current,values:k,orientation:d})),[a,u,k,d])},s.createElement(b,null,n)))}));Slider.displayName=E;const T=s.createContext({}),O=s.forwardRef(((e,t)=>{const{min:n,max:r,dir:i,children:a,onSlideStart:u,onSlideMove:l,onStepKeyDown:c}=e,d=h(e,["min","max","dir","children","onSlideStart","onSlideMove","onStepKeyDown"]),f=s.useRef(null),v=o(t,f),S=s.useRef(),g=function({ref:e,directionProp:t}){const[n,r]=s.useState("ltr"),[o,i]=s.useState(),a=s.useRef(0);return s.useEffect((()=>{if(void 0===t){const t=getComputedStyle(e.current);i(t)}}),[t,e]),s.useEffect((()=>{function e(){a.current=requestAnimationFrame((()=>{const t=null==o?void 0:o.direction;t&&r(t),e()}))}return void 0===t&&e(),()=>cancelAnimationFrame(a.current)}),[o,t,r]),t||n}({ref:f,directionProp:i}),y="ltr"===g;function b(e){const t=S.current||f.current.getBoundingClientRect(),o=F([0,t.width],y?[n,r]:[r,n]);return S.current=t,o(e-t.left)}return s.createElement(P,p({},d,{ref:v,style:m(m({},d.style),{},{"--radix-slider-thumb-transform":"translateX(-50%)"}),"data-orientation":"horizontal",onSlideMouseDown:e=>{const t=b(e.clientX);null==u||u(t)},onSlideMouseMove:e=>{const t=b(e.clientX);null==l||l(t)},onSlideMouseUp:()=>S.current=void 0,onSlideTouchStart:e=>{const t=b(e.targetTouches[0].clientX);null==u||u(t)},onSlideTouchMove:e=>{const t=b(e.targetTouches[0].clientX);null==l||l(t)},onSlideTouchEnd:()=>S.current=void 0,onStepKeyDown:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((e=>{const t=w[g].includes(e.key);null==c||c({event:e,direction:t?-1:1})}))}),s.createElement(T.Provider,{value:s.useMemo((()=>({startEdge:"left",endEdge:"right",size:"width"})),[])},y?a:s.createElement("span",{style:{flexGrow:1,display:"flex",alignItems:"center",transform:"rotate(180deg)"}},a)))})),R=s.forwardRef(((e,t)=>{const{min:n,max:r,children:i,onSlideStart:a,onSlideMove:u,onStepKeyDown:l}=e,c=h(e,["min","max","children","onSlideStart","onSlideMove","onStepKeyDown"]),d=s.useRef(null),f=o(t,d),v=s.useRef();function S(e){const t=v.current||d.current.getBoundingClientRect(),o=F([0,t.height],[r,n]);return v.current=t,o(e-t.top)}return s.createElement(P,p({},c,{ref:f,style:m(m({},c.style),{},{"--radix-slider-thumb-transform":"translateY(50%)"}),"data-orientation":"vertical",onSlideMouseDown:e=>{const t=S(e.clientY);null==a||a(t)},onSlideMouseMove:e=>{const t=S(e.clientY);null==u||u(t)},onSlideMouseUp:()=>v.current=void 0,onSlideTouchStart:e=>{const t=S(e.targetTouches[0].clientY);null==a||a(t)},onSlideTouchMove:e=>{const t=S(e.targetTouches[0].clientY);null==u||u(t)},onSlideTouchEnd:()=>v.current=void 0,onStepKeyDown:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((e=>{const t=w.ltr.includes(e.key);null==l||l({event:e,direction:t?-1:1})}))}),s.createElement(T.Provider,{value:s.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height"})),[])},i))})),P=s.forwardRef(((e,r)=>{const{as:o=x,selector:i=c(E),onSlideMouseDown:u,onSlideMouseMove:l,onSlideMouseUp:d,onSlideTouchStart:m,onSlideTouchMove:f,onSlideTouchEnd:w,onHomeKeyDown:g,onEndKeyDown:y,onStepKeyDown:b}=e,M=h(e,["as","selector","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),D=a(l),T=a(f),O=a((()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",O),d()})),R=a((()=>{document.removeEventListener("touchmove",T),document.removeEventListener("touchend",R),w()}));return s.useEffect((()=>()=>{O(),R()}),[O,R]),s.createElement(t,p({},M,{as:o,selector:i,ref:r,onMouseDown:n(e.onMouseDown,(e=>{0===e.button&&(H(e.target)||u(e),document.addEventListener("mousemove",D),document.addEventListener("mouseup",O))})),onTouchStart:n(e.onTouchStart,(e=>{H(e.target)?e.target.focus():m(e),document.addEventListener("touchmove",T),document.addEventListener("touchend",R),e.preventDefault()})),onKeyDown:n(e.onKeyDown,(e=>{"Home"===e.key?g(e):"End"===e.key?y(e):v.concat(S).includes(e.key)&&(b(e),e.preventDefault())})),onPointerDown:n(e.onPointerDown,(e=>{e.target.setPointerCapture(e.pointerId)})),onPointerUp:n(e.onPointerUp,(e=>{e.target.releasePointerCapture(e.pointerId)}))}))})),j="SliderTrack",K="span";export const SliderTrack=s.forwardRef(((e,n)=>{const{as:r=K,selector:o=c(j)}=e,i=h(e,["as","selector"]),a=D(j);return s.createElement(t,p({},i,{as:r,selector:o,ref:n,"data-orientation":a.orientation}))}));SliderTrack.displayName=j;const k="SliderRange",C="span";export const SliderRange=s.forwardRef(((e,n)=>{const{as:r=C,selector:i=c(k)}=e,a=h(e,["as","selector"]),u=D(k),l=s.useContext(T),d=s.useRef(null),f=o(n,d),v=u.values.length,S=u.values.map((e=>z(e,u.min,u.max))),w=v>1?Math.min(...S):0,g=100-Math.max(...S);return s.createElement(t,p({},a,{as:r,selector:i,ref:f,style:m(m({},e.style),{},{[l.startEdge]:w+"%",[l.endEdge]:g+"%"}),"data-orientation":u.orientation}))}));SliderRange.displayName=k;const A="SliderThumb",L="span";export const SliderThumb=s.forwardRef(((e,t)=>{const{ref:n,index:r}=y(),i=o(t,n),a=D(A).values[r];return void 0!==a?s.createElement(U,p({},e,{ref:i,index:r,value:a})):null}));const U=s.forwardRef(((e,r)=>{const{as:i=L,selector:a=c(A),index:l,value:d}=e,m=h(e,["as","selector","index","value"]),f=D(A),v=s.useContext(T),S=s.useRef(null),w=o(r,S),g=u(S),y=z(d,f.min,f.max),b=function(e,t){return t>2?"Value ".concat(e+1," of ").concat(t):2===t?["Minimum","Maximum"][e]:void 0}(l,f.values.length),E=null==g?void 0:g[v.size],x=E?function(e,t){const n=e/2,r=F([0,50],[0,n]);return n-r(t)}(E,y):0;return s.useEffect((()=>{const e=S.current;if(e)return f.thumbs.add(e),()=>{f.thumbs.delete(e)}}),[f.thumbs]),s.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[v.startEdge]:"calc(".concat(y,"% + ").concat(x,"px)")}},s.createElement(t,p({},m,{as:i,selector:a,ref:w,"aria-label":e["aria-label"]||b,"aria-valuemin":f.min,"aria-valuenow":d,"aria-valuemax":f.max,"aria-orientation":f.orientation,"data-orientation":f.orientation,role:"slider",tabIndex:0,onFocus:n(e.onFocus,(()=>{f.valueIndexToChangeRef.current=l}))})))}));SliderThumb.displayName=A;const I=e=>{const{value:t}=e,n=h(e,["value"]),r=s.useRef(null);return s.useEffect((()=>{const e=r.current,n=window.HTMLInputElement.prototype,{set:o}=Object.getOwnPropertyDescriptor(n,"value");if(o){const n=new Event("input",{bubbles:!0});o.call(e,t),e.dispatchEvent(n)}}),[t]),s.createElement("input",p({hidden:!0},n,{ref:r}))};function H(e){const t="data-".concat(c(A));return""===e.getAttribute(t)}function z(e,t,n){return 100/(n-t)*(e-t)}function F(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}export const Root=Slider;export const Track=SliderTrack;export const Range=SliderRange;export const Thumb=SliderThumb; | ||
import{createCollection as e}from"@radix-ui/react-collection";import{Primitive as t}from"@radix-ui/react-primitive";import{composeEventHandlers as n,createContext as o,useComposedRefs as r,useControlledState as i,useCallbackRef as u,useSize as a}from"@radix-ui/react-utils";import{clamp as c,getSelector as l}from"@radix-ui/utils";import*as s from"react";function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function m(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(){return(p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function v(e,t){if(null==e)return{};var n,o,r=function(e,t){if(null==e)return{};var n,o,r={},i=Object.keys(e);for(o=0;o<i.length;o++)n=i[o],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)n=i[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}const S=["PageUp","PageDown"],h=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],w={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[g,y]=e("Slider"),b=g((e=>s.createElement(s.Fragment,null,e.children))),E="Slider",x="span",[M,D]=o("SliderContext",E);export const Slider=s.forwardRef(((e,t)=>{const{name:n,min:o=0,max:u=100,step:a=1,orientation:l="horizontal",disabled:d=!1,minStepsBetweenThumbs:m=0,defaultValue:f=[o],value:w,onValueChange:g=(()=>{})}=e,y=v(e,["name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),E=Math.max(a,1),x=s.useRef(null),D=r(t,x),T=s.useRef(new Set),P=s.useRef(0),j="horizontal"===l?O:R,[K=[],k]=i({prop:w,defaultProp:f,onChange:g});function C(e,t){const n=Math.round((e-o)/E)*E+o,r=c(n,[o,u]);return new Promise((e=>{k(((n=[])=>{const o=function(e=[],t,n){const o=[...e];return o[n]=t,o.sort(((e,t)=>e-t))}(n,r,t);return function(e,t){if(t>0){const n=function(e){return e.slice(0,-1).map(((t,n)=>e[n+1]-t))}(e);return Math.min(...n)>=t}return!0}(o,m*E)?(P.current=o.indexOf(r),e(P.current),o[t]!==n[t]?o:n):(e(P.current),n)}))}))}function A(e){var t;null===(t=[...T.current][e])||void 0===t||t.focus()}return s.createElement(M.Provider,{value:s.useMemo((()=>({min:o,max:u,valueIndexToChangeRef:P,thumbs:T.current,values:K,orientation:l})),[o,u,K,l])},s.createElement(b,null,s.createElement(j,p({},y,{ref:D,min:o,max:u,"aria-disabled":d,"data-disabled":d,onSlideStart:d?void 0:function(e){C(e,function(e,t){if(1===e.length)return 0;const n=e.map((e=>Math.abs(e-t))),o=Math.min(...n);return n.indexOf(o)}(K,e)).then((e=>{window.setTimeout((()=>A(e)),0)}))},onSlideMove:d?void 0:function(e){C(e,P.current).then(A)},onHomeKeyDown:()=>!d&&C(o,0),onEndKeyDown:()=>!d&&C(u,K.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!d){const n=S.includes(e.key)||e.shiftKey&&h.includes(e.key)?10:1,o=P.current;C(K[o]+E*n*t,o)}}})),n&&K.map(((e,t)=>s.createElement(H,{key:t,name:n+(K.length>1?"[]":""),value:e,hidden:!0})))))}));Slider.displayName=E;const T=s.createContext({}),O=s.forwardRef(((e,t)=>{const{min:n,max:o,dir:i,onSlideStart:u,onSlideMove:a,onStepKeyDown:c}=e,l=v(e,["min","max","dir","onSlideStart","onSlideMove","onStepKeyDown"]),d=s.useRef(null),f=r(t,d),S=s.useRef(),h=function({ref:e,directionProp:t}){const[n,o]=s.useState("ltr"),[r,i]=s.useState(),u=s.useRef(0);return s.useEffect((()=>{if(void 0===t){const t=getComputedStyle(e.current);i(t)}}),[t,e]),s.useEffect((()=>{function e(){u.current=requestAnimationFrame((()=>{const t=null==r?void 0:r.direction;t&&o(t),e()}))}return void 0===t&&e(),()=>cancelAnimationFrame(u.current)}),[r,t,o]),t||n}({ref:d,directionProp:i}),g="ltr"===h;function y(e){const t=S.current||d.current.getBoundingClientRect(),r=F([0,t.width],g?[n,o]:[o,n]);return S.current=t,r(e-t.left)}return s.createElement(T.Provider,{value:s.useMemo((()=>({startEdge:g?"left":"right",endEdge:g?"right":"left",direction:g?1:-1,size:"width"})),[g])},s.createElement(P,p({},l,{ref:f,style:m(m({},l.style),{},{"--radix-slider-thumb-transform":"translateX(-50%)"}),"data-orientation":"horizontal",onSlideMouseDown:e=>{const t=y(e.clientX);null==u||u(t)},onSlideMouseMove:e=>{const t=y(e.clientX);null==a||a(t)},onSlideMouseUp:()=>S.current=void 0,onSlideTouchStart:e=>{const t=y(e.targetTouches[0].clientX);null==u||u(t)},onSlideTouchMove:e=>{const t=y(e.targetTouches[0].clientX);null==a||a(t)},onSlideTouchEnd:()=>S.current=void 0,onStepKeyDown:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((e=>{const t=w[h].includes(e.key);null==c||c({event:e,direction:t?-1:1})}))})))})),R=s.forwardRef(((e,t)=>{const{min:n,max:o,onSlideStart:i,onSlideMove:u,onStepKeyDown:a}=e,c=v(e,["min","max","onSlideStart","onSlideMove","onStepKeyDown"]),l=s.useRef(null),d=r(t,l),f=s.useRef();function S(e){const t=f.current||l.current.getBoundingClientRect(),r=F([0,t.height],[o,n]);return f.current=t,r(e-t.top)}return s.createElement(T.Provider,{value:s.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height",direction:1})),[])},s.createElement(P,p({},c,{ref:d,style:m(m({},c.style),{},{"--radix-slider-thumb-transform":"translateY(50%)"}),"data-orientation":"vertical",onSlideMouseDown:e=>{const t=S(e.clientY);null==i||i(t)},onSlideMouseMove:e=>{const t=S(e.clientY);null==u||u(t)},onSlideMouseUp:()=>f.current=void 0,onSlideTouchStart:e=>{const t=S(e.targetTouches[0].clientY);null==i||i(t)},onSlideTouchMove:e=>{const t=S(e.targetTouches[0].clientY);null==u||u(t)},onSlideTouchEnd:()=>f.current=void 0,onStepKeyDown:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((e=>{const t=w.ltr.includes(e.key);null==a||a({event:e,direction:t?-1:1})}))})))})),P=s.forwardRef(((e,o)=>{const{as:r=x,selector:i=l(E),onSlideMouseDown:a,onSlideMouseMove:c,onSlideMouseUp:d,onSlideTouchStart:m,onSlideTouchMove:f,onSlideTouchEnd:w,onHomeKeyDown:g,onEndKeyDown:y,onStepKeyDown:b}=e,M=v(e,["as","selector","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),D=u(c),T=u(f),O=u((()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",O),d()})),R=u((()=>{document.removeEventListener("touchmove",T),document.removeEventListener("touchend",R),w()}));return s.useEffect((()=>()=>{O(),R()}),[O,R]),s.createElement(t,p({},M,{as:r,selector:i,ref:o,onMouseDown:n(e.onMouseDown,(e=>{0===e.button&&(I(e.target)||a(e),document.addEventListener("mousemove",D),document.addEventListener("mouseup",O))})),onTouchStart:n(e.onTouchStart,(e=>{I(e.target)?e.target.focus():m(e),document.addEventListener("touchmove",T),document.addEventListener("touchend",R),e.preventDefault()})),onKeyDown:n(e.onKeyDown,(e=>{"Home"===e.key?g(e):"End"===e.key?y(e):S.concat(h).includes(e.key)&&(b(e),e.preventDefault())})),onPointerDown:n(e.onPointerDown,(e=>{e.target.setPointerCapture(e.pointerId)})),onPointerUp:n(e.onPointerUp,(e=>{e.target.releasePointerCapture(e.pointerId)}))}))})),j="SliderTrack",K="span";export const SliderTrack=s.forwardRef(((e,n)=>{const{as:o=K,selector:r=l(j)}=e,i=v(e,["as","selector"]),u=D(j);return s.createElement(t,p({},i,{as:o,selector:r,ref:n,"data-orientation":u.orientation}))}));SliderTrack.displayName=j;const k="SliderRange",C="span";export const SliderRange=s.forwardRef(((e,n)=>{const{as:o=C,selector:i=l(k)}=e,u=v(e,["as","selector"]),a=D(k),c=s.useContext(T),d=s.useRef(null),f=r(n,d),S=a.values.length,h=a.values.map((e=>z(e,a.min,a.max))),w=S>1?Math.min(...h):0,g=100-Math.max(...h);return s.createElement(t,p({},u,{as:o,selector:i,ref:f,style:m(m({},e.style),{},{[c.startEdge]:w+"%",[c.endEdge]:g+"%"}),"data-orientation":a.orientation}))}));SliderRange.displayName=k;const A="SliderThumb",L="span";export const SliderThumb=s.forwardRef(((e,t)=>{const{ref:n,index:o}=y(),i=r(t,n),u=D(A).values[o];return void 0!==u?s.createElement(U,p({},e,{ref:i,index:o,value:u})):null}));const U=s.forwardRef(((e,o)=>{const{as:i=L,selector:u=l(A),index:c,value:d}=e,m=v(e,["as","selector","index","value"]),f=D(A),S=s.useContext(T),h=s.useRef(null),w=r(o,h),g=a(h),y=z(d,f.min,f.max),b=function(e,t){return t>2?"Value ".concat(e+1," of ").concat(t):2===t?["Minimum","Maximum"][e]:void 0}(c,f.values.length),E=null==g?void 0:g[S.size],x=E?function(e,t,n){const o=e/2,r=F([0,50],[0,o]);return(o-r(t)*n)*n}(E,y,S.direction):0;return s.useEffect((()=>{const e=h.current;if(e)return f.thumbs.add(e),()=>{f.thumbs.delete(e)}}),[f.thumbs]),s.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[S.startEdge]:"calc(".concat(y,"% + ").concat(x,"px)")}},s.createElement(t,p({},m,{as:i,selector:u,ref:w,"aria-label":e["aria-label"]||b,"aria-valuemin":f.min,"aria-valuenow":d,"aria-valuemax":f.max,"aria-orientation":f.orientation,"data-orientation":f.orientation,role:"slider",tabIndex:0,onFocus:n(e.onFocus,(()=>{f.valueIndexToChangeRef.current=c}))})))}));SliderThumb.displayName=A;const H=e=>{const{value:t}=e,n=v(e,["value"]),o=s.useRef(null);return s.useEffect((()=>{const e=o.current,n=window.HTMLInputElement.prototype,{set:r}=Object.getOwnPropertyDescriptor(n,"value");if(r){const n=new Event("input",{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}}),[t]),s.createElement("input",p({hidden:!0},n,{ref:o}))};function I(e){const t="data-".concat(l(A));return""===e.getAttribute(t)}function z(e,t,n){return 100/(n-t)*(e-t)}function F(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const o=(t[1]-t[0])/(e[1]-e[0]);return t[0]+o*(n-e[0])}}export const Root=Slider;export const Track=SliderTrack;export const Range=SliderRange;export const Thumb=SliderThumb; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@radix-ui/react-slider", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"license": "MIT", | ||
@@ -19,6 +19,6 @@ "source": "src/index.ts", | ||
"dependencies": { | ||
"@radix-ui/react-collection": "0.0.3", | ||
"@radix-ui/react-polymorphic": "0.0.3", | ||
"@radix-ui/react-primitive": "0.0.2", | ||
"@radix-ui/react-utils": "0.0.3", | ||
"@radix-ui/react-collection": "0.0.4", | ||
"@radix-ui/react-polymorphic": "0.0.4", | ||
"@radix-ui/react-primitive": "0.0.3", | ||
"@radix-ui/react-utils": "0.0.4", | ||
"@radix-ui/utils": "0.0.3" | ||
@@ -25,0 +25,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
120482
139
+ Added@radix-ui/react-collection@0.0.4(transitive)
+ Added@radix-ui/react-polymorphic@0.0.4(transitive)
+ Added@radix-ui/react-primitive@0.0.3(transitive)
+ Added@radix-ui/react-utils@0.0.4(transitive)
- Removed@radix-ui/react-collection@0.0.3(transitive)
- Removed@radix-ui/react-polymorphic@0.0.3(transitive)
- Removed@radix-ui/react-primitive@0.0.2(transitive)
- Removed@radix-ui/react-utils@0.0.3(transitive)
Updated@radix-ui/react-utils@0.0.4