@radix-ui/react-slider
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
var e,n,t=require("@radix-ui/react-collection").createCollection,r=require("@radix-ui/react-polymorphic").forwardRefWithAs,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.getPartDataAttr,m=f.getPartDataAttrObj,p=(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 h(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 y(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?h(Object(t),!0).forEach((function(n){S(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):h(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 b(){return(b=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 g(e){return function(e){if(Array.isArray(e))return M(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||x(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 w(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 E(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)||x(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 x(e,n){if(e){if("string"==typeof e)return M(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)?M(e,n):void 0}}function M(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 O=["PageUp","PageDown"],D=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],T={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},P=E(t("Slider"),2),j=P[0],R=P[1],A=j((function(e){return p.createElement(p.Fragment,null,e.children)})),C=E(u("SliderContext","Slider"),2),K=C[0],k=C[1],I=r((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,h=void 0===v?"horizontal":v,y=e.disabled,S=void 0!==y&&y,x=e.minStepsBetweenThumbs,M=void 0===x?0:x,T=e.defaultValue,P=void 0===T?[i]:T,j=e.value,R=e.onValueChange,C=void 0===R?function(){}:R,k=w(e,["children","name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),I=Math.max(f,1),L=p.useRef(null),z=a(n,L),q=p.useRef(new Set),F=p.useRef(0),V="horizontal"===h?U:H,X=E(l({prop:j,defaultProp:P,onChange:C}),2),N=X[0],_=void 0===N?[]:N,W=X[1];function $(e,n){var t=Math.round((e-i)/I)*I+i,r=s(t,[i,c]);return new Promise((function(e){W((function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=B(t,r,n);return G(o,M*I)?(F.current=o.indexOf(r),e(F.current),o[n]!==t[n]?o:t):(e(F.current),t)}))}))}function J(e){var n;null===(n=g(q.current)[e])||void 0===n||n.focus()}return p.createElement(V,b({},k,m("Slider"),{ref:z,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,g(t));return t.indexOf(r)}(_,e)).then((function(e){window.setTimeout((function(){return J(e)}),0)}))},onSlideMove:S?void 0:function(e){$(e,F.current).then(J)},onHomeKeyDown:function(){return!S&&$(i,0)},onEndKeyDown:function(){return!S&&$(c,_.length-1)},onStepKeyDown:function(e){var n=e.event,t=e.direction;if(!S){var r=O.includes(n.key)||n.shiftKey&&D.includes(n.key)?10:1,o=F.current;$(_[o]+I*r*t,o)}}}),r&&_.map((function(e,n){return p.createElement(Y,{key:n,name:r+(_.length>1?"[]":""),value:e,hidden:!0})})),p.createElement(K.Provider,{value:p.useMemo((function(){return{min:i,max:c,valueIndexToChangeRef:F,thumbs:q.current,values:_,orientation:h}}),[i,c,_,h])},p.createElement(A,null,t)))}));exports.Slider=I,I.displayName="Slider";var L=p.createContext({}),U=r((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=w(e,["min","max","dir","children","onSlideStart","onSlideMove","onStepKeyDown"]),f=p.useRef(null),s=a(n,f),v=p.useRef(),m=function(e){var n=e.ref,t=e.directionProp,r=E(p.useState("ltr"),2),o=r[0],i=r[1],u=E(p.useState(),2),a=u[0],l=u[1],c=p.useRef(0);return p.useEffect((function(){if(void 0===t){var e=getComputedStyle(n.current);l(e)}}),[t,n]),p.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}),h="ltr"===m;function g(e){var n=v.current||f.current.getBoundingClientRect(),o=W([0,n.width],h?[t,r]:[r,t]);return v.current=n,o(e-n.left)}return p.createElement(z,b({},d,{ref:s,style:y(y({},d.style),{},S({},"--radix-slider-thumb-transform","translateX(-50%)")),"data-orientation":"horizontal",onSlideMouseDown:function(e){var n=g(e.clientX);null==u||u(n)},onSlideMouseMove:function(e){var n=g(e.clientX);null==l||l(n)},onSlideMouseUp:function(){return v.current=void 0},onSlideTouchStart:function(e){var n=g(e.targetTouches[0].clientX);null==u||u(n)},onSlideTouchMove:function(e){var n=g(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[m].includes(e.key);null==c||c({event:e,direction:n?-1:1})}))}),p.createElement(L.Provider,{value:p.useMemo((function(){return{startEdge:"left",endEdge:"right",size:"width"}}),[])},h?i:p.createElement("span",{style:{flexGrow:1,display:"flex",alignItems:"center",transform:"rotate(180deg)"}},i)))})),H=r((function(e,n){var t=e.min,r=e.max,o=e.children,i=e.onSlideStart,u=e.onSlideMove,l=e.onStepKeyDown,c=w(e,["min","max","children","onSlideStart","onSlideMove","onStepKeyDown"]),d=p.useRef(null),f=a(n,d),s=p.useRef();function v(e){var n=s.current||d.current.getBoundingClientRect(),o=W([0,n.height],[r,t]);return s.current=n,o(e-n.top)}return p.createElement(z,b({},c,{ref:f,style:y(y({},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})}))}),p.createElement(L.Provider,{value:p.useMemo((function(){return{startEdge:"bottom",endEdge:"top",size:"height"}}),[])},o))})),z=r((function(e,n){var t=e.as,r=void 0===t?"span":t,o=e.onSlideMouseDown,u=e.onSlideMouseMove,a=e.onSlideMouseUp,l=e.onSlideTouchStart,d=e.onSlideTouchMove,f=e.onSlideTouchEnd,s=e.onHomeKeyDown,v=e.onEndKeyDown,m=e.onStepKeyDown,h=w(e,["as","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),y=c(u),S=c(d),g=c((function(){document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",g),a()})),E=c((function(){document.removeEventListener("touchmove",S),document.removeEventListener("touchend",E),f()}));return p.useEffect((function(){return function(){g(),E()}}),[g,E]),p.createElement(r,b({},h,{ref:n,onMouseDown:i(e.onMouseDown,(function(e){0===e.button&&(N(e.target)||o(e),document.addEventListener("mousemove",y),document.addEventListener("mouseup",g))})),onTouchStart:i(e.onTouchStart,(function(e){N(e.target)?e.target.focus():l(e),document.addEventListener("touchmove",S),document.addEventListener("touchend",E),e.preventDefault()})),onKeyDown:i(e.onKeyDown,(function(e){"Home"===e.key?s(e):"End"===e.key?v(e):O.concat(D).includes(e.key)&&(m(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)}))}))})),q=r((function(e,n){var t=e.as,r=void 0===t?"span":t,o=e.children,i=w(e,["as","children"]),u=k("SliderTrack");return p.createElement(r,b({},m("SliderTrack"),i,{ref:n,"data-orientation":u.orientation}),o)}));exports.SliderTrack=q,q.displayName="SliderTrack";var F=r((function(e,n){var t,r=e.as,o=void 0===r?"span":r,i=e.style,u=w(e,["as","style"]),l=k("SliderRange"),c=p.useContext(L),d=p.useRef(null),f=a(n,d),s=l.values.length,v=l.values.map((function(e){return _(e,l.min,l.max)})),h=s>1?Math.min.apply(Math,g(v)):0,E=100-Math.max.apply(Math,g(v));return p.createElement(o,b({},m("SliderRange"),u,{ref:f,style:y(y({},i),{},(t={},S(t,c.startEdge,h+"%"),S(t,c.endEdge,E+"%"),t)),"data-orientation":l.orientation}))}));exports.SliderRange=F,F.displayName="SliderRange";var V=r((function(e,n){var t=R(),r=t.ref,o=t.index,i=a(n,r),u=k("SliderThumb").values[o];return void 0!==u?p.createElement(X,b({},e,{ref:i,index:o,value:u})):null}));exports.SliderThumb=V;var X=r((function(e,n){var t,r,o,u=e.as,l=void 0===u?"span":u,c=e.index,f=e.value,s=w(e,["as","index","value"]),v=k("SliderThumb"),h=p.useContext(L),y=p.useRef(null),g=a(n,y),E=d(y),x=_(f,v.min,v.max),M=function(e,n){return n>2?"Value ".concat(e+1," of ").concat(n):2===n?["Minimum","Maximum"][e]:void 0}(c,v.values.length),O=null==E?void 0:E[h.size],D=O?(t=x,o=W([0,50],[0,r=O/2]),r-o(t)):0;return p.useEffect((function(){var e=y.current;if(e)return v.thumbs.add(e),function(){v.thumbs.delete(e)}}),[v.thumbs]),p.createElement("span",{style:S({transform:"var(--radix-slider-thumb-transform)",position:"absolute"},h.startEdge,"calc(".concat(x,"% + ").concat(D,"px)"))},p.createElement(l,b({},s,m("SliderThumb"),{ref:g,"aria-label":e["aria-label"]||M,"aria-valuemin":v.min,"aria-valuenow":f,"aria-valuemax":v.max,"aria-orientation":v.orientation,role:"slider",tabIndex:0,onFocus:i(e.onFocus,(function(){v.valueIndexToChangeRef.current=c})),"data-orientation":v.orientation})))}));V.displayName="SliderThumb";var Y=function(e){var n=e.value,t=w(e,["value"]),r=p.useRef(null);return p.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]),p.createElement("input",b({hidden:!0},t,{ref:r}))};function B(){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=g(e);return r[t]=n,r.sort((function(e,n){return e-n}))}function N(e){var n=v("SliderThumb");return""===e.getAttribute(n)}function _(e,n,t){return 100/(t-n)*(e-n)}function G(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,g(t))>=n}return!0}function W(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 $=I;exports.Root=$;var J=q;exports.Track=J;var Q=F;exports.Range=Q;var Z=V;exports.Thumb=Z; | ||
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.onSlideMouseDown,o=e.onSlideMouseMove,u=e.onSlideMouseUp,a=e.onSlideTouchStart,l=e.onSlideTouchMove,d=e.onSlideTouchEnd,f=e.onHomeKeyDown,s=e.onEndKeyDown,p=e.onStepKeyDown,h=g(e,["onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),S=c(o),b=c(l),w=c((function(){document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",w),u()})),E=c((function(){document.removeEventListener("touchmove",b),document.removeEventListener("touchend",E),d()}));return m.useEffect((function(){return function(){w(),E()}}),[w,E]),m.createElement(r,y({as:"span",selector:v("Slider")},h,{ref:n,onMouseDown:i(e.onMouseDown,(function(e){0===e.button&&(B(e.target)||t(e),document.addEventListener("mousemove",S),document.addEventListener("mouseup",w))})),onTouchStart:i(e.onTouchStart,(function(e){B(e.target)?e.target.focus():a(e),document.addEventListener("touchmove",b),document.addEventListener("touchend",E),e.preventDefault()})),onKeyDown:i(e.onKeyDown,(function(e){"Home"===e.key?f(e):"End"===e.key?s(e):M.concat(O).includes(e.key)&&(p(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=K("SliderTrack");return m.createElement(r,y({as:"span",selector:v("SliderTrack")},e,{ref:n,"data-orientation":t.orientation}))}));exports.SliderTrack=z,z.displayName="SliderTrack";var q=m.forwardRef((function(e,n){var t,o=K("SliderRange"),i=m.useContext(I),u=m.useRef(null),l=a(n,u),c=o.values.length,d=o.values.map((function(e){return N(e,o.min,o.max)})),f=c>1?Math.min.apply(Math,b(d)):0,s=100-Math.max.apply(Math,b(d));return m.createElement(r,y({as:"span",selector:v("SliderRange")},e,{ref:l,style:h(h({},e.style),{},(t={},S(t,i.startEdge,f+"%"),S(t,i.endEdge,s+"%"),t)),"data-orientation":o.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.index,c=e.value,f=g(e,["index","value"]),s=K("SliderThumb"),p=m.useContext(I),h=m.useRef(null),b=a(n,h),w=d(h),E=N(c,s.min,s.max),x=function(e,n){return n>2?"Value ".concat(e+1," of ").concat(n):2===n?["Minimum","Maximum"][e]:void 0}(l,s.values.length),M=null==w?void 0:w[p.size],O=M?(t=E,u=G([0,50],[0,o=M/2]),o-u(t)):0;return m.useEffect((function(){var e=h.current;if(e)return s.thumbs.add(e),function(){s.thumbs.delete(e)}}),[s.thumbs]),m.createElement("span",{style:S({transform:"var(--radix-slider-thumb-transform)",position:"absolute"},p.startEdge,"calc(".concat(E,"% + ").concat(O,"px)"))},m.createElement(r,y({as:"span",selector:v("SliderThumb")},f,{ref:b,"aria-label":e["aria-label"]||x,"aria-valuemin":s.min,"aria-valuenow":c,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,role:"slider",tabIndex:0,onFocus:i(e.onFocus,(function(){s.valueIndexToChangeRef.current=l}))})))}));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; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{createCollection as e}from"@radix-ui/react-collection";import{forwardRefWithAs as n}from"@radix-ui/react-polymorphic";import{composeEventHandlers as t,createContext as r,useComposedRefs as o,useControlledState as i,useCallbackRef as u,useSize as a}from"@radix-ui/react-utils";import{clamp as l,getPartDataAttr as c,getPartDataAttrObj as s}from"@radix-ui/utils";import*as d from"react";function m(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 f(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?m(Object(t),!0).forEach((function(n){p(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):m(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function p(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function h(){return(h=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 S(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}const v=["PageUp","PageDown"],g=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],y={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[w,b]=e("Slider"),E=w((e=>d.createElement(d.Fragment,null,e.children))),x="span",[M,T]=r("SliderContext","Slider");export const Slider=n(((e,n)=>{const{children:t,name:r,min:u=0,max:a=100,step:c=1,orientation:m="horizontal",disabled:f=!1,minStepsBetweenThumbs:p=0,defaultValue:y=[u],value:w,onValueChange:b=(()=>{})}=e,x=S(e,["children","name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),T=Math.max(c,1),D=d.useRef(null),R=o(n,D),j=d.useRef(new Set),K=d.useRef(0),k="horizontal"===m?O:P,[C=[],L]=i({prop:w,defaultProp:y,onChange:b});function U(e,n){const t=Math.round((e-u)/T)*T+u,r=l(t,[u,a]);return new Promise((e=>{L(((t=[])=>{const o=function(e=[],n,t){const r=[...e];return r[t]=n,r.sort(((e,n)=>e-n))}(t,r,n);return function(e,n){if(n>0){const t=function(e){return e.slice(0,-1).map(((n,t)=>e[t+1]-n))}(e);return Math.min(...t)>=n}return!0}(o,p*T)?(K.current=o.indexOf(r),e(K.current),o[n]!==t[n]?o:t):(e(K.current),t)}))}))}function I(e){var n;null===(n=[...j.current][e])||void 0===n||n.focus()}return d.createElement(k,h({},x,s("Slider"),{ref:R,min:u,max:a,"aria-disabled":f,"data-disabled":f,onSlideStart:f?void 0:function(e){U(e,function(e,n){if(1===e.length)return 0;const t=e.map((e=>Math.abs(e-n))),r=Math.min(...t);return t.indexOf(r)}(C,e)).then((e=>{window.setTimeout((()=>I(e)),0)}))},onSlideMove:f?void 0:function(e){U(e,K.current).then(I)},onHomeKeyDown:()=>!f&&U(u,0),onEndKeyDown:()=>!f&&U(a,C.length-1),onStepKeyDown:({event:e,direction:n})=>{if(!f){const t=v.includes(e.key)||e.shiftKey&&g.includes(e.key)?10:1,r=K.current;U(C[r]+T*t*n,r)}}}),r&&C.map(((e,n)=>d.createElement(A,{key:n,name:r+(C.length>1?"[]":""),value:e,hidden:!0}))),d.createElement(M.Provider,{value:d.useMemo((()=>({min:u,max:a,valueIndexToChangeRef:K,thumbs:j.current,values:C,orientation:m})),[u,a,C,m])},d.createElement(E,null,t)))}));Slider.displayName="Slider";const D=d.createContext({}),O=n(((e,n)=>{const{min:t,max:r,dir:i,children:u,onSlideStart:a,onSlideMove:l,onStepKeyDown:c}=e,s=S(e,["min","max","dir","children","onSlideStart","onSlideMove","onStepKeyDown"]),m=d.useRef(null),p=o(n,m),v=d.useRef(),g=function({ref:e,directionProp:n}){const[t,r]=d.useState("ltr"),[o,i]=d.useState(),u=d.useRef(0);return d.useEffect((()=>{if(void 0===n){const n=getComputedStyle(e.current);i(n)}}),[n,e]),d.useEffect((()=>{function e(){u.current=requestAnimationFrame((()=>{const n=null==o?void 0:o.direction;n&&r(n),e()}))}return void 0===n&&e(),()=>cancelAnimationFrame(u.current)}),[o,n,r]),n||t}({ref:m,directionProp:i}),w="ltr"===g;function b(e){const n=v.current||m.current.getBoundingClientRect(),o=I([0,n.width],w?[t,r]:[r,t]);return v.current=n,o(e-n.left)}return d.createElement(R,h({},s,{ref:p,style:f(f({},s.style),{},{"--radix-slider-thumb-transform":"translateX(-50%)"}),"data-orientation":"horizontal",onSlideMouseDown:e=>{const n=b(e.clientX);null==a||a(n)},onSlideMouseMove:e=>{const n=b(e.clientX);null==l||l(n)},onSlideMouseUp:()=>v.current=void 0,onSlideTouchStart:e=>{const n=b(e.targetTouches[0].clientX);null==a||a(n)},onSlideTouchMove:e=>{const n=b(e.targetTouches[0].clientX);null==l||l(n)},onSlideTouchEnd:()=>v.current=void 0,onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((e=>{const n=y[g].includes(e.key);null==c||c({event:e,direction:n?-1:1})}))}),d.createElement(D.Provider,{value:d.useMemo((()=>({startEdge:"left",endEdge:"right",size:"width"})),[])},w?u:d.createElement("span",{style:{flexGrow:1,display:"flex",alignItems:"center",transform:"rotate(180deg)"}},u)))})),P=n(((e,n)=>{const{min:t,max:r,children:i,onSlideStart:u,onSlideMove:a,onStepKeyDown:l}=e,c=S(e,["min","max","children","onSlideStart","onSlideMove","onStepKeyDown"]),s=d.useRef(null),m=o(n,s),p=d.useRef();function v(e){const n=p.current||s.current.getBoundingClientRect(),o=I([0,n.height],[r,t]);return p.current=n,o(e-n.top)}return d.createElement(R,h({},c,{ref:m,style:f(f({},c.style),{},{"--radix-slider-thumb-transform":"translateY(50%)"}),"data-orientation":"vertical",onSlideMouseDown:e=>{const n=v(e.clientY);null==u||u(n)},onSlideMouseMove:e=>{const n=v(e.clientY);null==a||a(n)},onSlideMouseUp:()=>p.current=void 0,onSlideTouchStart:e=>{const n=v(e.targetTouches[0].clientY);null==u||u(n)},onSlideTouchMove:e=>{const n=v(e.targetTouches[0].clientY);null==a||a(n)},onSlideTouchEnd:()=>p.current=void 0,onStepKeyDown:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}((e=>{const n=y.ltr.includes(e.key);null==l||l({event:e,direction:n?-1:1})}))}),d.createElement(D.Provider,{value:d.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height"})),[])},i))})),R=n(((e,n)=>{const{as:r=x,onSlideMouseDown:o,onSlideMouseMove:i,onSlideMouseUp:a,onSlideTouchStart:l,onSlideTouchMove:c,onSlideTouchEnd:s,onHomeKeyDown:m,onEndKeyDown:f,onStepKeyDown:p}=e,y=S(e,["as","onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),w=u(i),b=u(c),E=u((()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",E),a()})),M=u((()=>{document.removeEventListener("touchmove",b),document.removeEventListener("touchend",M),s()}));return d.useEffect((()=>()=>{E(),M()}),[E,M]),d.createElement(r,h({},y,{ref:n,onMouseDown:t(e.onMouseDown,(e=>{0===e.button&&(L(e.target)||o(e),document.addEventListener("mousemove",w),document.addEventListener("mouseup",E))})),onTouchStart:t(e.onTouchStart,(e=>{L(e.target)?e.target.focus():l(e),document.addEventListener("touchmove",b),document.addEventListener("touchend",M),e.preventDefault()})),onKeyDown:t(e.onKeyDown,(e=>{"Home"===e.key?m(e):"End"===e.key?f(e):v.concat(g).includes(e.key)&&(p(e),e.preventDefault())})),onPointerDown:t(e.onPointerDown,(e=>{e.target.setPointerCapture(e.pointerId)})),onPointerUp:t(e.onPointerUp,(e=>{e.target.releasePointerCapture(e.pointerId)}))}))})),j="span";export const SliderTrack=n(((e,n)=>{const{as:t=j,children:r}=e,o=S(e,["as","children"]),i=T("SliderTrack");return d.createElement(t,h({},s("SliderTrack"),o,{ref:n,"data-orientation":i.orientation}),r)}));SliderTrack.displayName="SliderTrack";const K="span";export const SliderRange=n(((e,n)=>{const{as:t=K,style:r}=e,i=S(e,["as","style"]),u=T("SliderRange"),a=d.useContext(D),l=d.useRef(null),c=o(n,l),m=u.values.length,p=u.values.map((e=>U(e,u.min,u.max))),v=m>1?Math.min(...p):0,g=100-Math.max(...p);return d.createElement(t,h({},s("SliderRange"),i,{ref:c,style:f(f({},r),{},{[a.startEdge]:v+"%",[a.endEdge]:g+"%"}),"data-orientation":u.orientation}))}));SliderRange.displayName="SliderRange";const k="span";export const SliderThumb=n(((e,n)=>{const{ref:t,index:r}=b(),i=o(n,t),u=T("SliderThumb").values[r];return void 0!==u?d.createElement(C,h({},e,{ref:i,index:r,value:u})):null}));const C=n(((e,n)=>{const{as:r=k,index:i,value:u}=e,l=S(e,["as","index","value"]),c=T("SliderThumb"),m=d.useContext(D),f=d.useRef(null),p=o(n,f),v=a(f),g=U(u,c.min,c.max),y=function(e,n){return n>2?"Value ".concat(e+1," of ").concat(n):2===n?["Minimum","Maximum"][e]:void 0}(i,c.values.length),w=null==v?void 0:v[m.size],b=w?function(e,n){const t=e/2,r=I([0,50],[0,t]);return t-r(n)}(w,g):0;return d.useEffect((()=>{const e=f.current;if(e)return c.thumbs.add(e),()=>{c.thumbs.delete(e)}}),[c.thumbs]),d.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[m.startEdge]:"calc(".concat(g,"% + ").concat(b,"px)")}},d.createElement(r,h({},l,s("SliderThumb"),{ref:p,"aria-label":e["aria-label"]||y,"aria-valuemin":c.min,"aria-valuenow":u,"aria-valuemax":c.max,"aria-orientation":c.orientation,role:"slider",tabIndex:0,onFocus:t(e.onFocus,(()=>{c.valueIndexToChangeRef.current=i})),"data-orientation":c.orientation})))}));SliderThumb.displayName="SliderThumb";const A=e=>{const{value:n}=e,t=S(e,["value"]),r=d.useRef(null);return d.useEffect((()=>{const e=r.current,t=window.HTMLInputElement.prototype,{set:o}=Object.getOwnPropertyDescriptor(t,"value");if(o){const t=new Event("input",{bubbles:!0});o.call(e,n),e.dispatchEvent(t)}}),[n]),d.createElement("input",h({hidden:!0},t,{ref:r}))};function L(e){const n=c("SliderThumb");return""===e.getAttribute(n)}function U(e,n,t){return 100/(t-n)*(e-n)}function I(e,n){return t=>{if(e[0]===e[1]||n[0]===n[1])return n[0];const r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-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 r,useComposedRefs as o,useControlledState as i,useCallbackRef as u,useSize as a}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 S(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 h=["PageUp","PageDown"],v=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],g={ltr:["ArrowDown","Home","ArrowLeft","PageUp"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[w,y]=e("Slider"),b=w((e=>s.createElement(s.Fragment,null,e.children))),[E,x]=r("SliderContext","Slider");export const Slider=s.forwardRef(((e,t)=>{const{children:n,name:r,min:u=0,max:a=100,step:c=1,orientation:d="horizontal",disabled:m=!1,minStepsBetweenThumbs:f=0,defaultValue:g=[u],value:w,onValueChange:y=(()=>{})}=e,x=S(e,["children","name","min","max","step","orientation","disabled","minStepsBetweenThumbs","defaultValue","value","onValueChange"]),M=Math.max(c,1),O=s.useRef(null),R=o(t,O),j=s.useRef(new Set),K=s.useRef(0),k="horizontal"===d?T:D,[C=[],A]=i({prop:w,defaultProp:g,onChange:y});function L(e,t){const n=Math.round((e-u)/M)*M+u,r=l(n,[u,a]);return new Promise((e=>{A(((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*M)?(K.current=o.indexOf(r),e(K.current),o[t]!==n[t]?o:n):(e(K.current),n)}))}))}function U(e){var t;null===(t=[...j.current][e])||void 0===t||t.focus()}return s.createElement(k,p({},x,{ref:R,min:u,max:a,"aria-disabled":m,"data-disabled":m,onSlideStart:m?void 0:function(e){L(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)}(C,e)).then((e=>{window.setTimeout((()=>U(e)),0)}))},onSlideMove:m?void 0:function(e){L(e,K.current).then(U)},onHomeKeyDown:()=>!m&&L(u,0),onEndKeyDown:()=>!m&&L(a,C.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!m){const n=h.includes(e.key)||e.shiftKey&&v.includes(e.key)?10:1,r=K.current;L(C[r]+M*n*t,r)}}}),r&&C.map(((e,t)=>s.createElement(P,{key:t,name:r+(C.length>1?"[]":""),value:e,hidden:!0}))),s.createElement(E.Provider,{value:s.useMemo((()=>({min:u,max:a,valueIndexToChangeRef:K,thumbs:j.current,values:C,orientation:d})),[u,a,C,d])},s.createElement(b,null,n)))}));Slider.displayName="Slider";const M=s.createContext({}),T=s.forwardRef(((e,t)=>{const{min:n,max:r,dir:i,children:u,onSlideStart:a,onSlideMove:l,onStepKeyDown:c}=e,d=S(e,["min","max","dir","children","onSlideStart","onSlideMove","onStepKeyDown"]),f=s.useRef(null),h=o(t,f),v=s.useRef(),w=function({ref:e,directionProp:t}){const[n,r]=s.useState("ltr"),[o,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==o?void 0:o.direction;t&&r(t),e()}))}return void 0===t&&e(),()=>cancelAnimationFrame(u.current)}),[o,t,r]),t||n}({ref:f,directionProp:i}),y="ltr"===w;function b(e){const t=v.current||f.current.getBoundingClientRect(),o=k([0,t.width],y?[n,r]:[r,n]);return v.current=t,o(e-t.left)}return s.createElement(O,p({},d,{ref:h,style:m(m({},d.style),{},{"--radix-slider-thumb-transform":"translateX(-50%)"}),"data-orientation":"horizontal",onSlideMouseDown:e=>{const t=b(e.clientX);null==a||a(t)},onSlideMouseMove:e=>{const t=b(e.clientX);null==l||l(t)},onSlideMouseUp:()=>v.current=void 0,onSlideTouchStart:e=>{const t=b(e.targetTouches[0].clientX);null==a||a(t)},onSlideTouchMove:e=>{const t=b(e.targetTouches[0].clientX);null==l||l(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=g[w].includes(e.key);null==c||c({event:e,direction:t?-1:1})}))}),s.createElement(M.Provider,{value:s.useMemo((()=>({startEdge:"left",endEdge:"right",size:"width"})),[])},y?u:s.createElement("span",{style:{flexGrow:1,display:"flex",alignItems:"center",transform:"rotate(180deg)"}},u)))})),D=s.forwardRef(((e,t)=>{const{min:n,max:r,children:i,onSlideStart:u,onSlideMove:a,onStepKeyDown:l}=e,c=S(e,["min","max","children","onSlideStart","onSlideMove","onStepKeyDown"]),d=s.useRef(null),f=o(t,d),h=s.useRef();function v(e){const t=h.current||d.current.getBoundingClientRect(),o=k([0,t.height],[r,n]);return h.current=t,o(e-t.top)}return s.createElement(O,p({},c,{ref:f,style:m(m({},c.style),{},{"--radix-slider-thumb-transform":"translateY(50%)"}),"data-orientation":"vertical",onSlideMouseDown:e=>{const t=v(e.clientY);null==u||u(t)},onSlideMouseMove:e=>{const t=v(e.clientY);null==a||a(t)},onSlideMouseUp:()=>h.current=void 0,onSlideTouchStart:e=>{const t=v(e.targetTouches[0].clientY);null==u||u(t)},onSlideTouchMove:e=>{const t=v(e.targetTouches[0].clientY);null==a||a(t)},onSlideTouchEnd:()=>h.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=g.ltr.includes(e.key);null==l||l({event:e,direction:t?-1:1})}))}),s.createElement(M.Provider,{value:s.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height"})),[])},i))})),O=s.forwardRef(((e,r)=>{const{onSlideMouseDown:o,onSlideMouseMove:i,onSlideMouseUp:a,onSlideTouchStart:l,onSlideTouchMove:d,onSlideTouchEnd:m,onHomeKeyDown:f,onEndKeyDown:g,onStepKeyDown:w}=e,y=S(e,["onSlideMouseDown","onSlideMouseMove","onSlideMouseUp","onSlideTouchStart","onSlideTouchMove","onSlideTouchEnd","onHomeKeyDown","onEndKeyDown","onStepKeyDown"]),b=u(i),E=u(d),x=u((()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",x),a()})),M=u((()=>{document.removeEventListener("touchmove",E),document.removeEventListener("touchend",M),m()}));return s.useEffect((()=>()=>{x(),M()}),[x,M]),s.createElement(t,p({as:"span",selector:c("Slider")},y,{ref:r,onMouseDown:n(e.onMouseDown,(e=>{0===e.button&&(j(e.target)||o(e),document.addEventListener("mousemove",b),document.addEventListener("mouseup",x))})),onTouchStart:n(e.onTouchStart,(e=>{j(e.target)?e.target.focus():l(e),document.addEventListener("touchmove",E),document.addEventListener("touchend",M),e.preventDefault()})),onKeyDown:n(e.onKeyDown,(e=>{"Home"===e.key?f(e):"End"===e.key?g(e):h.concat(v).includes(e.key)&&(w(e),e.preventDefault())})),onPointerDown:n(e.onPointerDown,(e=>{e.target.setPointerCapture(e.pointerId)})),onPointerUp:n(e.onPointerUp,(e=>{e.target.releasePointerCapture(e.pointerId)}))}))}));export const SliderTrack=s.forwardRef(((e,n)=>{const r=x("SliderTrack");return s.createElement(t,p({as:"span",selector:c("SliderTrack")},e,{ref:n,"data-orientation":r.orientation}))}));SliderTrack.displayName="SliderTrack";export const SliderRange=s.forwardRef(((e,n)=>{const r=x("SliderRange"),i=s.useContext(M),u=s.useRef(null),a=o(n,u),l=r.values.length,d=r.values.map((e=>K(e,r.min,r.max))),f=l>1?Math.min(...d):0,S=100-Math.max(...d);return s.createElement(t,p({as:"span",selector:c("SliderRange")},e,{ref:a,style:m(m({},e.style),{},{[i.startEdge]:f+"%",[i.endEdge]:S+"%"}),"data-orientation":r.orientation}))}));SliderRange.displayName="SliderRange";export const SliderThumb=s.forwardRef(((e,t)=>{const{ref:n,index:r}=y(),i=o(t,n),u=x("SliderThumb").values[r];return void 0!==u?s.createElement(R,p({},e,{ref:i,index:r,value:u})):null}));const R=s.forwardRef(((e,r)=>{const{index:i,value:u}=e,l=S(e,["index","value"]),d=x("SliderThumb"),m=s.useContext(M),f=s.useRef(null),h=o(r,f),v=a(f),g=K(u,d.min,d.max),w=function(e,t){return t>2?"Value ".concat(e+1," of ").concat(t):2===t?["Minimum","Maximum"][e]:void 0}(i,d.values.length),y=null==v?void 0:v[m.size],b=y?function(e,t){const n=e/2,r=k([0,50],[0,n]);return n-r(t)}(y,g):0;return s.useEffect((()=>{const e=f.current;if(e)return d.thumbs.add(e),()=>{d.thumbs.delete(e)}}),[d.thumbs]),s.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[m.startEdge]:"calc(".concat(g,"% + ").concat(b,"px)")}},s.createElement(t,p({as:"span",selector:c("SliderThumb")},l,{ref:h,"aria-label":e["aria-label"]||w,"aria-valuemin":d.min,"aria-valuenow":u,"aria-valuemax":d.max,"aria-orientation":d.orientation,"data-orientation":d.orientation,role:"slider",tabIndex:0,onFocus:n(e.onFocus,(()=>{d.valueIndexToChangeRef.current=i}))})))}));SliderThumb.displayName="SliderThumb";const P=e=>{const{value:t}=e,n=S(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 j(e){const t="data-".concat(c("SliderThumb"));return""===e.getAttribute(t)}function K(e,t,n){return 100/(n-t)*(e-t)}function k(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; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@radix-ui/react-slider", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"license": "MIT", | ||
@@ -21,10 +21,8 @@ "source": "src/index.ts", | ||
"dependencies": { | ||
"@radix-ui/react-collection": "0.0.1", | ||
"@radix-ui/react-polymorphic": "0.0.1", | ||
"@radix-ui/react-utils": "0.0.1", | ||
"@radix-ui/utils": "0.0.1" | ||
"@radix-ui/react-collection": "0.0.2", | ||
"@radix-ui/react-polymorphic": "0.0.2", | ||
"@radix-ui/react-primitive": "0.0.1", | ||
"@radix-ui/react-utils": "0.0.2", | ||
"@radix-ui/utils": "0.0.2" | ||
}, | ||
"devDependencies": { | ||
"parcel": "^2.0.0-beta.1" | ||
}, | ||
"peerDependencies": { | ||
@@ -31,0 +29,0 @@ "react": "^16.8 || ^17.0" |
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
117633
0
6
+ Added@radix-ui/react-collection@0.0.2(transitive)
+ Added@radix-ui/react-polymorphic@0.0.2(transitive)
+ Added@radix-ui/react-primitive@0.0.1(transitive)
+ Added@radix-ui/react-utils@0.0.2(transitive)
+ Added@radix-ui/utils@0.0.2(transitive)
- Removed@radix-ui/react-collection@0.0.1(transitive)
- Removed@radix-ui/react-polymorphic@0.0.1(transitive)
- Removed@radix-ui/react-utils@0.0.1(transitive)
- Removed@radix-ui/utils@0.0.1(transitive)
Updated@radix-ui/react-utils@0.0.2
Updated@radix-ui/utils@0.0.2