@radix-ui/react-slider
Advanced tools
Comparing version 0.1.1-rc.9 to 0.1.1-rc.10
@@ -1,2 +0,2 @@ | ||
var e,t,n,r=require("@radix-ui/react-collection").createCollection,o=require("@radix-ui/react-primitive").Primitive,i=require("@radix-ui/react-use-size").useSize,a=require("@radix-ui/react-use-previous").usePrevious,u=require("@radix-ui/react-use-direction").useDirection,l=require("@radix-ui/react-use-controllable-state").useControllableState,s=require("@radix-ui/react-context").createContext,d=require("@radix-ui/react-compose-refs").useComposedRefs,c=require("@radix-ui/primitive").composeEventHandlers,f=require("@radix-ui/number").clamp,m=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e),p=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const v=["PageUp","PageDown"],h=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],x={ltr:["ArrowDown","Home","ArrowLeft","PageDown"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[S,w,g,b]=r(),[y,E]=s("Slider"),R=/*#__PURE__*/m.forwardRef(((e,t)=>{const{name:n,min:r=0,max:o=100,step:i=1,orientation:a="horizontal",disabled:u=!1,minStepsBetweenThumbs:s=0,defaultValue:c=[r],value:x,onValueChange:g=(()=>{}),...b}=e,[E,R]=m.useState(null),D=d(t,(e=>R(e))),C=m.useRef(new Set),K=m.useRef(0),k="horizontal"===a,q=!E||Boolean(E.closest("form")),I=k?M:P,[z=[],A]=l({prop:x,defaultProp:c,onChange:e=>{var t;null===(t=[...C.current][K.current])||void 0===t||t.focus(),g(e)}});function H(e,t){const n=function(e){return(String(e).split(".")[1]||"").length}(i),a=function(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}(Math.round((e-r)/i)*i+r,n),u=f(a,[r,o]);A(((e=[])=>{const n=function(e=[],t,n){const r=[...e];return r[n]=t,r.sort(((e,t)=>e-t))}(e,u,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}(n,s*i)?(K.current=n.indexOf(u),String(n)===String(e)?e:n):e}))}/*#__PURE__*/return m.createElement(y,{disabled:u,min:r,max:o,valueIndexToChangeRef:K,thumbs:C.current,values:z,orientation:a},/*#__PURE__*/m.createElement(S,null,/*#__PURE__*/m.createElement(w,null,/*#__PURE__*/m.createElement(I,p({"aria-disabled":u,"data-disabled":u?"":void 0},b,{ref:D,min:r,max:o,onSlideStart:u?void 0:function(e){H(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)}(z,e))},onSlideMove:u?void 0:function(e){H(e,K.current)},onHomeKeyDown:()=>!u&&H(r,0),onEndKeyDown:()=>!u&&H(o,z.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!u){const n=v.includes(e.key)||e.shiftKey&&h.includes(e.key)?10:1,r=K.current;H(z[r]+i*n*t,r)}}})))),q&&z.map(((e,t)=>/*#__PURE__*/m.createElement(T,{key:t,name:n?n+(z.length>1?"[]":""):void 0,value:e}))))}));exports.Slider=R;const D=/*#__PURE__*/m.createContext({}),M=/*#__PURE__*/m.forwardRef(((e,t)=>{const{min:n,max:r,dir:o,onSlideStart:i,onSlideMove:a,onStepKeyDown:l,...s}=e,[c,f]=m.useState(null),v=d(t,(e=>f(e))),h=m.useRef(),S=u(c,o),w="ltr"===S;function g(e){const t=h.current||c.getBoundingClientRect(),o=A([0,t.width],w?[n,r]:[r,n]);return h.current=t,o(e-t.left)}/*#__PURE__*/return m.createElement(D.Provider,{value:m.useMemo((()=>({startEdge:w?"left":"right",endEdge:w?"right":"left",direction:w?1:-1,size:"width"})),[w])},/*#__PURE__*/m.createElement(C,p({"data-orientation":"horizontal"},s,{ref:v,style:{...s.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:e=>{const t=g(e.clientX);null==i||i(t)},onSlideMove:e=>{const t=g(e.clientX);null==a||a(t)},onSlideEnd:()=>h.current=void 0,onStepKeyDown:e=>{const t=x[S].includes(e.key);null==l||l({event:e,direction:t?-1:1})}})))})),P=/*#__PURE__*/m.forwardRef(((e,t)=>{const{min:n,max:r,onSlideStart:o,onSlideMove:i,onStepKeyDown:a,...u}=e,l=m.useRef(null),s=d(t,l),c=m.useRef();function f(e){const t=c.current||l.current.getBoundingClientRect(),o=A([0,t.height],[r,n]);return c.current=t,o(e-t.top)}/*#__PURE__*/return m.createElement(D.Provider,{value:m.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height",direction:1})),[])},/*#__PURE__*/m.createElement(C,p({"data-orientation":"vertical"},u,{ref:s,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:e=>{const t=f(e.clientY);null==o||o(t)},onSlideMove:e=>{const t=f(e.clientY);null==i||i(t)},onSlideEnd:()=>c.current=void 0,onStepKeyDown:e=>{const t=x.ltr.includes(e.key);null==a||a({event:e,direction:t?-1:1})}})))})),C=/*#__PURE__*/m.forwardRef(((e,t)=>{const{onSlideStart:n,onSlideMove:r,onSlideEnd:i,onHomeKeyDown:a,onEndKeyDown:u,onStepKeyDown:l,...s}=e,d=E("Slider");/*#__PURE__*/return m.createElement(o.span,p({},s,{ref:t,onKeyDown:c(e.onKeyDown,(e=>{"Home"===e.key?a(e):"End"===e.key?u(e):v.concat(h).includes(e.key)&&(l(e),e.preventDefault())})),onPointerDown:c(e.onPointerDown,(e=>{const t=e.target;t.setPointerCapture(e.pointerId),e.preventDefault(),d.thumbs.has(t)?t.focus():n(e)})),onPointerMove:c(e.onPointerMove,(e=>{e.target.hasPointerCapture(e.pointerId)&&r(e)})),onPointerUp:c(e.onPointerUp,(e=>{const t=e.target;t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),i(e))}))}))})),K=/*#__PURE__*/m.forwardRef(((e,t)=>{const n=E("SliderTrack");/*#__PURE__*/return m.createElement(o.span,p({"data-disabled":n.disabled?"":void 0,"data-orientation":n.orientation},e,{ref:t}))}));exports.SliderTrack=K;const k=/*#__PURE__*/m.forwardRef(((e,t)=>{const n=E("SliderRange"),r=m.useContext(D),i=m.useRef(null),a=d(t,i),u=n.values.length,l=n.values.map((e=>z(e,n.min,n.max))),s=u>1?Math.min(...l):0,c=100-Math.max(...l);/*#__PURE__*/return m.createElement(o.span,p({"data-orientation":n.orientation,"data-disabled":n.disabled?"":void 0},e,{ref:a,style:{...e.style,[r.startEdge]:s+"%",[r.endEdge]:c+"%"}}))}));exports.SliderRange=k;const q=/*#__PURE__*/m.forwardRef(((e,t)=>{const{getItems:n}=b(),[r,o]=m.useState(null),i=d(t,(e=>o(e))),a=m.useMemo((()=>r?n().findIndex((e=>e.ref.current===r)):-1),[n,r]);/*#__PURE__*/return m.createElement(I,p({},e,{ref:i,index:a}))}));exports.SliderThumb=q;const I=/*#__PURE__*/m.forwardRef(((e,t)=>{const{index:n,...r}=e,a=E("SliderThumb"),u=m.useContext(D),[l,s]=m.useState(null),f=d(t,(e=>s(e))),v=i(l),h=a.values[n],x=void 0===h?0:z(h,a.min,a.max),S=function(e,t){return t>2?`Value ${e+1} of ${t}`:2===t?["Minimum","Maximum"][e]:void 0}(n,a.values.length),w=null==v?void 0:v[u.size],b=w?function(e,t,n){const r=e/2,o=A([0,50],[0,r]);return(r-o(t)*n)*n}(w,x,u.direction):0;return m.useEffect((()=>{if(l)return a.thumbs.add(l),()=>{a.thumbs.delete(l)}}),[l,a.thumbs]),/*#__PURE__*/m.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[u.startEdge]:`calc(${x}% + ${b}px)`}},/*#__PURE__*/m.createElement(g,null,/*#__PURE__*/m.createElement(o.span,p({role:"slider","aria-label":e["aria-label"]||S,"aria-valuemin":a.min,"aria-valuenow":h,"aria-valuemax":a.max,"aria-orientation":a.orientation,"data-orientation":a.orientation,"data-disabled":a.disabled?"":void 0,tabIndex:a.disabled?void 0:0},r,{ref:f,style:void 0===h?{display:"none"}:e.style,onFocus:c(e.onFocus,(()=>{a.valueIndexToChangeRef.current=n}))}))))})),T=e=>{const{value:t,...n}=e,r=m.useRef(null),o=a(t);return m.useEffect((()=>{const e=r.current,n=window.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,"value").set;if(o!==t&&i){const n=new Event("input",{bubbles:!0});i.call(e,t),e.dispatchEvent(n)}}),[o,t]),/*#__PURE__*/m.createElement("input",p({style:{display:"none"}},n,{ref:r,defaultValue:t}))};/*#__PURE__*/function z(e,t,n){return 100/(n-t)*(e-t)}function A(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])}}const H=R;exports.Root=H;const O=K;exports.Track=O;const B=k;exports.Range=B;const U=q;exports.Thumb=U; | ||
var e,t,n,r=require("@radix-ui/react-collection").createCollection,o=require("@radix-ui/react-primitive").Primitive,i=require("@radix-ui/react-use-size").useSize,a=require("@radix-ui/react-use-previous").usePrevious,u=require("@radix-ui/react-use-direction").useDirection,l=require("@radix-ui/react-use-controllable-state").useControllableState,s=require("@radix-ui/react-context").createContext,d=require("@radix-ui/react-compose-refs").useComposedRefs,c=require("@radix-ui/primitive").composeEventHandlers,f=require("@radix-ui/number").clamp,m=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e),p=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const v=["PageUp","PageDown"],h=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],x={ltr:["ArrowDown","Home","ArrowLeft","PageDown"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[S,w,g,b]=r(),[y,E]=s("Slider"),R=/*#__PURE__*/m.forwardRef(((e,t)=>{const{name:n,min:r=0,max:o=100,step:i=1,orientation:a="horizontal",disabled:u=!1,minStepsBetweenThumbs:s=0,defaultValue:c=[r],value:x,onValueChange:g=(()=>{}),...b}=e,[E,R]=m.useState(null),D=d(t,(e=>R(e))),C=m.useRef(new Set),K=m.useRef(0),k="horizontal"===a,q=!E||Boolean(E.closest("form")),T=k?M:P,[z=[],A]=l({prop:x,defaultProp:c,onChange:e=>{var t;null===(t=[...C.current][K.current])||void 0===t||t.focus(),g(e)}});function H(e,t){const n=function(e){return(String(e).split(".")[1]||"").length}(i),a=function(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}(Math.round((e-r)/i)*i+r,n),u=f(a,[r,o]);A(((e=[])=>{const n=function(e=[],t,n){const r=[...e];return r[n]=t,r.sort(((e,t)=>e-t))}(e,u,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}(n,s*i)?(K.current=n.indexOf(u),String(n)===String(e)?e:n):e}))}/*#__PURE__*/return m.createElement(y,{disabled:u,min:r,max:o,valueIndexToChangeRef:K,thumbs:C.current,values:z,orientation:a},/*#__PURE__*/m.createElement(S,null,/*#__PURE__*/m.createElement(w,null,/*#__PURE__*/m.createElement(T,p({"aria-disabled":u,"data-disabled":u?"":void 0},b,{ref:D,min:r,max:o,onSlideStart:u?void 0:function(e){H(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)}(z,e))},onSlideMove:u?void 0:function(e){H(e,K.current)},onHomeKeyDown:()=>!u&&H(r,0),onEndKeyDown:()=>!u&&H(o,z.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!u){const n=v.includes(e.key)||e.shiftKey&&h.includes(e.key)?10:1,r=K.current;H(z[r]+i*n*t,r)}}})))),q&&z.map(((e,t)=>/*#__PURE__*/m.createElement(I,{key:t,name:n?n+(z.length>1?"[]":""):void 0,value:e}))))}));exports.Slider=R;const D=/*#__PURE__*/m.createContext({}),M=/*#__PURE__*/m.forwardRef(((e,t)=>{const{min:n,max:r,dir:o,onSlideStart:i,onSlideMove:a,onStepKeyDown:l,...s}=e,[c,f]=m.useState(null),v=d(t,(e=>f(e))),h=m.useRef(),S=u(c,o),w="ltr"===S;function g(e){const t=h.current||c.getBoundingClientRect(),o=A([0,t.width],w?[n,r]:[r,n]);return h.current=t,o(e-t.left)}/*#__PURE__*/return m.createElement(D.Provider,{value:m.useMemo((()=>({startEdge:w?"left":"right",endEdge:w?"right":"left",direction:w?1:-1,size:"width"})),[w])},/*#__PURE__*/m.createElement(C,p({"data-orientation":"horizontal"},s,{ref:v,style:{...s.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:e=>{const t=g(e.clientX);null==i||i(t)},onSlideMove:e=>{const t=g(e.clientX);null==a||a(t)},onSlideEnd:()=>h.current=void 0,onStepKeyDown:e=>{const t=x[S].includes(e.key);null==l||l({event:e,direction:t?-1:1})}})))})),P=/*#__PURE__*/m.forwardRef(((e,t)=>{const{min:n,max:r,onSlideStart:o,onSlideMove:i,onStepKeyDown:a,...u}=e,l=m.useRef(null),s=d(t,l),c=m.useRef();function f(e){const t=c.current||l.current.getBoundingClientRect(),o=A([0,t.height],[r,n]);return c.current=t,o(e-t.top)}/*#__PURE__*/return m.createElement(D.Provider,{value:m.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height",direction:1})),[])},/*#__PURE__*/m.createElement(C,p({"data-orientation":"vertical"},u,{ref:s,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:e=>{const t=f(e.clientY);null==o||o(t)},onSlideMove:e=>{const t=f(e.clientY);null==i||i(t)},onSlideEnd:()=>c.current=void 0,onStepKeyDown:e=>{const t=x.ltr.includes(e.key);null==a||a({event:e,direction:t?-1:1})}})))})),C=/*#__PURE__*/m.forwardRef(((e,t)=>{const{onSlideStart:n,onSlideMove:r,onSlideEnd:i,onHomeKeyDown:a,onEndKeyDown:u,onStepKeyDown:l,...s}=e,d=E("Slider");/*#__PURE__*/return m.createElement(o.span,p({},s,{ref:t,onKeyDown:c(e.onKeyDown,(e=>{"Home"===e.key?a(e):"End"===e.key?u(e):v.concat(h).includes(e.key)&&(l(e),e.preventDefault())})),onPointerDown:c(e.onPointerDown,(e=>{const t=e.target;t.setPointerCapture(e.pointerId),e.preventDefault(),d.thumbs.has(t)?t.focus():n(e)})),onPointerMove:c(e.onPointerMove,(e=>{e.target.hasPointerCapture(e.pointerId)&&r(e)})),onPointerUp:c(e.onPointerUp,(e=>{const t=e.target;t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),i(e))}))}))})),K=/*#__PURE__*/m.forwardRef(((e,t)=>{const n=E("SliderTrack");/*#__PURE__*/return m.createElement(o.span,p({"data-disabled":n.disabled?"":void 0,"data-orientation":n.orientation},e,{ref:t}))}));exports.SliderTrack=K;const k=/*#__PURE__*/m.forwardRef(((e,t)=>{const n=E("SliderRange"),r=m.useContext(D),i=m.useRef(null),a=d(t,i),u=n.values.length,l=n.values.map((e=>z(e,n.min,n.max))),s=u>1?Math.min(...l):0,c=100-Math.max(...l);/*#__PURE__*/return m.createElement(o.span,p({"data-orientation":n.orientation,"data-disabled":n.disabled?"":void 0},e,{ref:a,style:{...e.style,[r.startEdge]:s+"%",[r.endEdge]:c+"%"}}))}));exports.SliderRange=k;const q=/*#__PURE__*/m.forwardRef(((e,t)=>{const n=b(),[r,o]=m.useState(null),i=d(t,(e=>o(e))),a=m.useMemo((()=>r?n().findIndex((e=>e.ref.current===r)):-1),[n,r]);/*#__PURE__*/return m.createElement(T,p({},e,{ref:i,index:a}))}));exports.SliderThumb=q;const T=/*#__PURE__*/m.forwardRef(((e,t)=>{const{index:n,...r}=e,a=E("SliderThumb"),u=m.useContext(D),[l,s]=m.useState(null),f=d(t,(e=>s(e))),v=i(l),h=a.values[n],x=void 0===h?0:z(h,a.min,a.max),S=function(e,t){return t>2?`Value ${e+1} of ${t}`:2===t?["Minimum","Maximum"][e]:void 0}(n,a.values.length),w=null==v?void 0:v[u.size],b=w?function(e,t,n){const r=e/2,o=A([0,50],[0,r]);return(r-o(t)*n)*n}(w,x,u.direction):0;return m.useEffect((()=>{if(l)return a.thumbs.add(l),()=>{a.thumbs.delete(l)}}),[l,a.thumbs]),/*#__PURE__*/m.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[u.startEdge]:`calc(${x}% + ${b}px)`}},/*#__PURE__*/m.createElement(g,null,/*#__PURE__*/m.createElement(o.span,p({role:"slider","aria-label":e["aria-label"]||S,"aria-valuemin":a.min,"aria-valuenow":h,"aria-valuemax":a.max,"aria-orientation":a.orientation,"data-orientation":a.orientation,"data-disabled":a.disabled?"":void 0,tabIndex:a.disabled?void 0:0},r,{ref:f,style:void 0===h?{display:"none"}:e.style,onFocus:c(e.onFocus,(()=>{a.valueIndexToChangeRef.current=n}))}))))})),I=e=>{const{value:t,...n}=e,r=m.useRef(null),o=a(t);return m.useEffect((()=>{const e=r.current,n=window.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,"value").set;if(o!==t&&i){const n=new Event("input",{bubbles:!0});i.call(e,t),e.dispatchEvent(n)}}),[o,t]),/*#__PURE__*/m.createElement("input",p({style:{display:"none"}},n,{ref:r,defaultValue:t}))};/*#__PURE__*/function z(e,t,n){return 100/(n-t)*(e-t)}function A(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])}}const H=R;exports.Root=H;const O=K;exports.Track=O;const B=k;exports.Range=B;const U=q;exports.Thumb=U; | ||
//# 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{useSize as n}from"@radix-ui/react-use-size";import{usePrevious as r}from"@radix-ui/react-use-previous";import{useDirection as o}from"@radix-ui/react-use-direction";import{useControllableState as i}from"@radix-ui/react-use-controllable-state";import{createContext as a}from"@radix-ui/react-context";import{useComposedRefs as l}from"@radix-ui/react-compose-refs";import{composeEventHandlers as u}from"@radix-ui/primitive";import{clamp as d}from"@radix-ui/number";import*as s from"react";import c from"@babel/runtime/helpers/esm/extends";const m=["PageUp","PageDown"],f=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],p={ltr:["ArrowDown","Home","ArrowLeft","PageDown"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[v,h,S,w]=e(),[x,g]=a("Slider");export const Slider=/*#__PURE__*/s.forwardRef(((e,t)=>{const{name:n,min:r=0,max:o=100,step:a=1,orientation:u="horizontal",disabled:p=!1,minStepsBetweenThumbs:S=0,defaultValue:w=[r],value:g,onValueChange:b=(()=>{}),...R}=e,[D,P]=s.useState(null),C=l(t,(e=>P(e))),K=s.useRef(new Set),k=s.useRef(0),T="horizontal"===u,I=!D||Boolean(D.closest("form")),A=T?y:E,[z=[],H]=i({prop:g,defaultProp:w,onChange:e=>{var t;null===(t=[...K.current][k.current])||void 0===t||t.focus(),b(e)}});function B(e,t){const n=function(e){return(String(e).split(".")[1]||"").length}(a),i=function(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}(Math.round((e-r)/a)*a+r,n),l=d(i,[r,o]);H(((e=[])=>{const n=function(e=[],t,n){const r=[...e];return r[n]=t,r.sort(((e,t)=>e-t))}(e,l,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}(n,S*a)?(k.current=n.indexOf(l),String(n)===String(e)?e:n):e}))}/*#__PURE__*/return s.createElement(x,{disabled:p,min:r,max:o,valueIndexToChangeRef:k,thumbs:K.current,values:z,orientation:u},/*#__PURE__*/s.createElement(v,null,/*#__PURE__*/s.createElement(h,null,/*#__PURE__*/s.createElement(A,c({"aria-disabled":p,"data-disabled":p?"":void 0},R,{ref:C,min:r,max:o,onSlideStart:p?void 0:function(e){B(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)}(z,e))},onSlideMove:p?void 0:function(e){B(e,k.current)},onHomeKeyDown:()=>!p&&B(r,0),onEndKeyDown:()=>!p&&B(o,z.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!p){const n=m.includes(e.key)||e.shiftKey&&f.includes(e.key)?10:1,r=k.current;B(z[r]+a*n*t,r)}}})))),I&&z.map(((e,t)=>/*#__PURE__*/s.createElement(M,{key:t,name:n?n+(z.length>1?"[]":""):void 0,value:e}))))}));/*#__PURE__*/const b=/*#__PURE__*/s.createContext({}),y=/*#__PURE__*/s.forwardRef(((e,t)=>{const{min:n,max:r,dir:i,onSlideStart:a,onSlideMove:u,onStepKeyDown:d,...m}=e,[f,v]=s.useState(null),h=l(t,(e=>v(e))),S=s.useRef(),w=o(f,i),x="ltr"===w;function g(e){const t=S.current||f.getBoundingClientRect(),o=C([0,t.width],x?[n,r]:[r,n]);return S.current=t,o(e-t.left)}/*#__PURE__*/return s.createElement(b.Provider,{value:s.useMemo((()=>({startEdge:x?"left":"right",endEdge:x?"right":"left",direction:x?1:-1,size:"width"})),[x])},/*#__PURE__*/s.createElement(R,c({"data-orientation":"horizontal"},m,{ref:h,style:{...m.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:e=>{const t=g(e.clientX);null==a||a(t)},onSlideMove:e=>{const t=g(e.clientX);null==u||u(t)},onSlideEnd:()=>S.current=void 0,onStepKeyDown:e=>{const t=p[w].includes(e.key);null==d||d({event:e,direction:t?-1:1})}})))})),E=/*#__PURE__*/s.forwardRef(((e,t)=>{const{min:n,max:r,onSlideStart:o,onSlideMove:i,onStepKeyDown:a,...u}=e,d=s.useRef(null),m=l(t,d),f=s.useRef();function v(e){const t=f.current||d.current.getBoundingClientRect(),o=C([0,t.height],[r,n]);return f.current=t,o(e-t.top)}/*#__PURE__*/return s.createElement(b.Provider,{value:s.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height",direction:1})),[])},/*#__PURE__*/s.createElement(R,c({"data-orientation":"vertical"},u,{ref:m,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:e=>{const t=v(e.clientY);null==o||o(t)},onSlideMove:e=>{const t=v(e.clientY);null==i||i(t)},onSlideEnd:()=>f.current=void 0,onStepKeyDown:e=>{const t=p.ltr.includes(e.key);null==a||a({event:e,direction:t?-1:1})}})))})),R=/*#__PURE__*/s.forwardRef(((e,n)=>{const{onSlideStart:r,onSlideMove:o,onSlideEnd:i,onHomeKeyDown:a,onEndKeyDown:l,onStepKeyDown:d,...p}=e,v=g("Slider");/*#__PURE__*/return s.createElement(t.span,c({},p,{ref:n,onKeyDown:u(e.onKeyDown,(e=>{"Home"===e.key?a(e):"End"===e.key?l(e):m.concat(f).includes(e.key)&&(d(e),e.preventDefault())})),onPointerDown:u(e.onPointerDown,(e=>{const t=e.target;t.setPointerCapture(e.pointerId),e.preventDefault(),v.thumbs.has(t)?t.focus():r(e)})),onPointerMove:u(e.onPointerMove,(e=>{e.target.hasPointerCapture(e.pointerId)&&o(e)})),onPointerUp:u(e.onPointerUp,(e=>{const t=e.target;t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),i(e))}))}))}));export const SliderTrack=/*#__PURE__*/s.forwardRef(((e,n)=>{const r=g("SliderTrack");/*#__PURE__*/return s.createElement(t.span,c({"data-disabled":r.disabled?"":void 0,"data-orientation":r.orientation},e,{ref:n}))}));/*#__PURE__*/export const SliderRange=/*#__PURE__*/s.forwardRef(((e,n)=>{const r=g("SliderRange"),o=s.useContext(b),i=s.useRef(null),a=l(n,i),u=r.values.length,d=r.values.map((e=>P(e,r.min,r.max))),m=u>1?Math.min(...d):0,f=100-Math.max(...d);/*#__PURE__*/return s.createElement(t.span,c({"data-orientation":r.orientation,"data-disabled":r.disabled?"":void 0},e,{ref:a,style:{...e.style,[o.startEdge]:m+"%",[o.endEdge]:f+"%"}}))}));/*#__PURE__*/export const SliderThumb=/*#__PURE__*/s.forwardRef(((e,t)=>{const{getItems:n}=w(),[r,o]=s.useState(null),i=l(t,(e=>o(e))),a=s.useMemo((()=>r?n().findIndex((e=>e.ref.current===r)):-1),[n,r]);/*#__PURE__*/return s.createElement(D,c({},e,{ref:i,index:a}))}));const D=/*#__PURE__*/s.forwardRef(((e,r)=>{const{index:o,...i}=e,a=g("SliderThumb"),d=s.useContext(b),[m,f]=s.useState(null),p=l(r,(e=>f(e))),v=n(m),h=a.values[o],w=void 0===h?0:P(h,a.min,a.max),x=function(e,t){return t>2?`Value ${e+1} of ${t}`:2===t?["Minimum","Maximum"][e]:void 0}(o,a.values.length),y=null==v?void 0:v[d.size],E=y?function(e,t,n){const r=e/2,o=C([0,50],[0,r]);return(r-o(t)*n)*n}(y,w,d.direction):0;return s.useEffect((()=>{if(m)return a.thumbs.add(m),()=>{a.thumbs.delete(m)}}),[m,a.thumbs]),/*#__PURE__*/s.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[d.startEdge]:`calc(${w}% + ${E}px)`}},/*#__PURE__*/s.createElement(S,null,/*#__PURE__*/s.createElement(t.span,c({role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":a.min,"aria-valuenow":h,"aria-valuemax":a.max,"aria-orientation":a.orientation,"data-orientation":a.orientation,"data-disabled":a.disabled?"":void 0,tabIndex:a.disabled?void 0:0},i,{ref:p,style:void 0===h?{display:"none"}:e.style,onFocus:u(e.onFocus,(()=>{a.valueIndexToChangeRef.current=o}))}))))})),M=e=>{const{value:t,...n}=e,o=s.useRef(null),i=r(t);return s.useEffect((()=>{const e=o.current,n=window.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,"value").set;if(i!==t&&r){const n=new Event("input",{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}}),[i,t]),/*#__PURE__*/s.createElement("input",c({style:{display:"none"}},n,{ref:o,defaultValue:t}))};/*#__PURE__*/function P(e,t,n){return 100/(n-t)*(e-t)}function C(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{useSize as n}from"@radix-ui/react-use-size";import{usePrevious as r}from"@radix-ui/react-use-previous";import{useDirection as o}from"@radix-ui/react-use-direction";import{useControllableState as i}from"@radix-ui/react-use-controllable-state";import{createContext as a}from"@radix-ui/react-context";import{useComposedRefs as l}from"@radix-ui/react-compose-refs";import{composeEventHandlers as u}from"@radix-ui/primitive";import{clamp as d}from"@radix-ui/number";import*as s from"react";import c from"@babel/runtime/helpers/esm/extends";const m=["PageUp","PageDown"],f=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],p={ltr:["ArrowDown","Home","ArrowLeft","PageDown"],rtl:["ArrowDown","Home","ArrowRight","PageDown"]},[v,h,S,w]=e(),[x,g]=a("Slider");export const Slider=/*#__PURE__*/s.forwardRef(((e,t)=>{const{name:n,min:r=0,max:o=100,step:a=1,orientation:u="horizontal",disabled:p=!1,minStepsBetweenThumbs:S=0,defaultValue:w=[r],value:g,onValueChange:b=(()=>{}),...R}=e,[D,P]=s.useState(null),C=l(t,(e=>P(e))),K=s.useRef(new Set),k=s.useRef(0),T="horizontal"===u,I=!D||Boolean(D.closest("form")),A=T?y:E,[z=[],H]=i({prop:g,defaultProp:w,onChange:e=>{var t;null===(t=[...K.current][k.current])||void 0===t||t.focus(),b(e)}});function B(e,t){const n=function(e){return(String(e).split(".")[1]||"").length}(a),i=function(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}(Math.round((e-r)/a)*a+r,n),l=d(i,[r,o]);H(((e=[])=>{const n=function(e=[],t,n){const r=[...e];return r[n]=t,r.sort(((e,t)=>e-t))}(e,l,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}(n,S*a)?(k.current=n.indexOf(l),String(n)===String(e)?e:n):e}))}/*#__PURE__*/return s.createElement(x,{disabled:p,min:r,max:o,valueIndexToChangeRef:k,thumbs:K.current,values:z,orientation:u},/*#__PURE__*/s.createElement(v,null,/*#__PURE__*/s.createElement(h,null,/*#__PURE__*/s.createElement(A,c({"aria-disabled":p,"data-disabled":p?"":void 0},R,{ref:C,min:r,max:o,onSlideStart:p?void 0:function(e){B(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)}(z,e))},onSlideMove:p?void 0:function(e){B(e,k.current)},onHomeKeyDown:()=>!p&&B(r,0),onEndKeyDown:()=>!p&&B(o,z.length-1),onStepKeyDown:({event:e,direction:t})=>{if(!p){const n=m.includes(e.key)||e.shiftKey&&f.includes(e.key)?10:1,r=k.current;B(z[r]+a*n*t,r)}}})))),I&&z.map(((e,t)=>/*#__PURE__*/s.createElement(M,{key:t,name:n?n+(z.length>1?"[]":""):void 0,value:e}))))}));/*#__PURE__*/const b=/*#__PURE__*/s.createContext({}),y=/*#__PURE__*/s.forwardRef(((e,t)=>{const{min:n,max:r,dir:i,onSlideStart:a,onSlideMove:u,onStepKeyDown:d,...m}=e,[f,v]=s.useState(null),h=l(t,(e=>v(e))),S=s.useRef(),w=o(f,i),x="ltr"===w;function g(e){const t=S.current||f.getBoundingClientRect(),o=C([0,t.width],x?[n,r]:[r,n]);return S.current=t,o(e-t.left)}/*#__PURE__*/return s.createElement(b.Provider,{value:s.useMemo((()=>({startEdge:x?"left":"right",endEdge:x?"right":"left",direction:x?1:-1,size:"width"})),[x])},/*#__PURE__*/s.createElement(R,c({"data-orientation":"horizontal"},m,{ref:h,style:{...m.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:e=>{const t=g(e.clientX);null==a||a(t)},onSlideMove:e=>{const t=g(e.clientX);null==u||u(t)},onSlideEnd:()=>S.current=void 0,onStepKeyDown:e=>{const t=p[w].includes(e.key);null==d||d({event:e,direction:t?-1:1})}})))})),E=/*#__PURE__*/s.forwardRef(((e,t)=>{const{min:n,max:r,onSlideStart:o,onSlideMove:i,onStepKeyDown:a,...u}=e,d=s.useRef(null),m=l(t,d),f=s.useRef();function v(e){const t=f.current||d.current.getBoundingClientRect(),o=C([0,t.height],[r,n]);return f.current=t,o(e-t.top)}/*#__PURE__*/return s.createElement(b.Provider,{value:s.useMemo((()=>({startEdge:"bottom",endEdge:"top",size:"height",direction:1})),[])},/*#__PURE__*/s.createElement(R,c({"data-orientation":"vertical"},u,{ref:m,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:e=>{const t=v(e.clientY);null==o||o(t)},onSlideMove:e=>{const t=v(e.clientY);null==i||i(t)},onSlideEnd:()=>f.current=void 0,onStepKeyDown:e=>{const t=p.ltr.includes(e.key);null==a||a({event:e,direction:t?-1:1})}})))})),R=/*#__PURE__*/s.forwardRef(((e,n)=>{const{onSlideStart:r,onSlideMove:o,onSlideEnd:i,onHomeKeyDown:a,onEndKeyDown:l,onStepKeyDown:d,...p}=e,v=g("Slider");/*#__PURE__*/return s.createElement(t.span,c({},p,{ref:n,onKeyDown:u(e.onKeyDown,(e=>{"Home"===e.key?a(e):"End"===e.key?l(e):m.concat(f).includes(e.key)&&(d(e),e.preventDefault())})),onPointerDown:u(e.onPointerDown,(e=>{const t=e.target;t.setPointerCapture(e.pointerId),e.preventDefault(),v.thumbs.has(t)?t.focus():r(e)})),onPointerMove:u(e.onPointerMove,(e=>{e.target.hasPointerCapture(e.pointerId)&&o(e)})),onPointerUp:u(e.onPointerUp,(e=>{const t=e.target;t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),i(e))}))}))}));export const SliderTrack=/*#__PURE__*/s.forwardRef(((e,n)=>{const r=g("SliderTrack");/*#__PURE__*/return s.createElement(t.span,c({"data-disabled":r.disabled?"":void 0,"data-orientation":r.orientation},e,{ref:n}))}));/*#__PURE__*/export const SliderRange=/*#__PURE__*/s.forwardRef(((e,n)=>{const r=g("SliderRange"),o=s.useContext(b),i=s.useRef(null),a=l(n,i),u=r.values.length,d=r.values.map((e=>P(e,r.min,r.max))),m=u>1?Math.min(...d):0,f=100-Math.max(...d);/*#__PURE__*/return s.createElement(t.span,c({"data-orientation":r.orientation,"data-disabled":r.disabled?"":void 0},e,{ref:a,style:{...e.style,[o.startEdge]:m+"%",[o.endEdge]:f+"%"}}))}));/*#__PURE__*/export const SliderThumb=/*#__PURE__*/s.forwardRef(((e,t)=>{const n=w(),[r,o]=s.useState(null),i=l(t,(e=>o(e))),a=s.useMemo((()=>r?n().findIndex((e=>e.ref.current===r)):-1),[n,r]);/*#__PURE__*/return s.createElement(D,c({},e,{ref:i,index:a}))}));const D=/*#__PURE__*/s.forwardRef(((e,r)=>{const{index:o,...i}=e,a=g("SliderThumb"),d=s.useContext(b),[m,f]=s.useState(null),p=l(r,(e=>f(e))),v=n(m),h=a.values[o],w=void 0===h?0:P(h,a.min,a.max),x=function(e,t){return t>2?`Value ${e+1} of ${t}`:2===t?["Minimum","Maximum"][e]:void 0}(o,a.values.length),y=null==v?void 0:v[d.size],E=y?function(e,t,n){const r=e/2,o=C([0,50],[0,r]);return(r-o(t)*n)*n}(y,w,d.direction):0;return s.useEffect((()=>{if(m)return a.thumbs.add(m),()=>{a.thumbs.delete(m)}}),[m,a.thumbs]),/*#__PURE__*/s.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[d.startEdge]:`calc(${w}% + ${E}px)`}},/*#__PURE__*/s.createElement(S,null,/*#__PURE__*/s.createElement(t.span,c({role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":a.min,"aria-valuenow":h,"aria-valuemax":a.max,"aria-orientation":a.orientation,"data-orientation":a.orientation,"data-disabled":a.disabled?"":void 0,tabIndex:a.disabled?void 0:0},i,{ref:p,style:void 0===h?{display:"none"}:e.style,onFocus:u(e.onFocus,(()=>{a.valueIndexToChangeRef.current=o}))}))))})),M=e=>{const{value:t,...n}=e,o=s.useRef(null),i=r(t);return s.useEffect((()=>{const e=o.current,n=window.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,"value").set;if(i!==t&&r){const n=new Event("input",{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}}),[i,t]),/*#__PURE__*/s.createElement("input",c({style:{display:"none"}},n,{ref:o,defaultValue:t}))};/*#__PURE__*/function P(e,t,n){return 100/(n-t)*(e-t)}function C(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.1.1-rc.9", | ||
"version": "0.1.1-rc.10", | ||
"license": "MIT", | ||
@@ -22,6 +22,6 @@ "source": "src/index.ts", | ||
"@radix-ui/primitive": "0.1.0", | ||
"@radix-ui/react-collection": "0.1.1-rc.9", | ||
"@radix-ui/react-collection": "0.1.1-rc.10", | ||
"@radix-ui/react-compose-refs": "0.1.0", | ||
"@radix-ui/react-context": "0.1.0", | ||
"@radix-ui/react-primitive": "0.1.1-rc.9", | ||
"@radix-ui/react-primitive": "0.1.1-rc.10", | ||
"@radix-ui/react-use-controllable-state": "0.1.0", | ||
@@ -28,0 +28,0 @@ "@radix-ui/react-use-direction": "0.1.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
98787
+ Added@radix-ui/react-collection@0.1.1-rc.10(transitive)
+ Added@radix-ui/react-primitive@0.1.1-rc.10(transitive)
+ Added@radix-ui/react-slot@0.1.1-rc.6(transitive)
- Removed@radix-ui/react-collection@0.1.1-rc.9(transitive)
- Removed@radix-ui/react-primitive@0.1.1-rc.9(transitive)
- Removed@radix-ui/react-slot@0.1.1-rc.5(transitive)