@zag-js/slider
Advanced tools
Comparing version 0.0.0-dev-20220407084218 to 0.0.0-dev-20220408111010
@@ -1,2 +0,2 @@ | ||
var S=Object.defineProperty,dt=Object.defineProperties,ft=Object.getOwnPropertyDescriptor,pt=Object.getOwnPropertyDescriptors,mt=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var j=(t,e,n)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,O=(t,e)=>{for(var n in e||(e={}))_.call(e,n)&&j(t,n,e[n]);if(H)for(var n of H(e))ht.call(e,n)&&j(t,n,e[n]);return t},R=(t,e)=>dt(t,pt(e)),gt=t=>S(t,"__esModule",{value:!0});var vt=(t,e)=>{for(var n in e)S(t,n,{get:e[n],enumerable:!0})},yt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mt(e))!_.call(t,o)&&(n||o!=="default")&&S(t,o,{get:()=>e[o],enumerable:!(r=ft(e,o))||r.enumerable});return t};var bt=(t=>(e,n)=>t&&t.get(e)||(n=yt(gt({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var ce={};vt(ce,{connect:()=>ut,machine:()=>st,unstable__dom:()=>i});var U=Math.pow,c=t=>t?"":void 0;function V(t){let e=new Set;function n(r){let o=globalThis.requestAnimationFrame(r);e.add(()=>globalThis.cancelAnimationFrame(o))}return n(()=>n(t)),function(){e.forEach(function(r){r()})}}function Y(t){let e=globalThis.requestAnimationFrame(t);return function(){globalThis.cancelAnimationFrame(e)}}var wt=()=>{},xt=(...t)=>e=>t.reduce((n,r)=>r(n),e),fe=(()=>{let t=0;return()=>(t++,t.toString(36))})(),D=t=>Et()&&t.test(navigator.platform),Et=()=>typeof window!="undefined",Tt=()=>D(/^Mac/),Pt=()=>D(/^iPhone/),St=()=>D(/^iPad/)||Tt()&&navigator.maxTouchPoints>1,$=()=>Pt()||St(),kt=t=>Array.isArray(t),Mt=t=>!(t==null||typeof t!="object"||kt(t)),At=t=>Mt(t)&&"button"in t,Lt=t=>t.button===0,b=new Map,v=new Map;function Ct(t,e,n,r){var o;if(!t)return wt;let a=JSON.stringify({type:e,options:r}),d=b.get(t);if(b.has(t))(d==null?void 0:d.has(a))?(o=d==null?void 0:d.get(a))==null||o.add(n):d==null||d.set(a,new Set([n]));else{let u=new Map([[a,new Set([n])]]);b.set(t,u)}function x(u){var m,f;function g(p){var l;let s=b.get(u);(l=s==null?void 0:s.get(a))==null||l.forEach(h=>h(p))}if(!(v==null?void 0:v.has(u))){v.set(u,new Map([[a,g]])),u.addEventListener(e,g,r);return}((m=v==null?void 0:v.get(u))==null?void 0:m.has(a))||((f=v.get(u))==null||f.set(a,g),u.addEventListener(e,g,r))}return x(t),function(){var u,m,f,g;if(!b.has(t))return;let p=b.get(t);if((u=p==null?void 0:p.get(a))==null||u.delete(n),((m=p==null?void 0:p.get(a))==null?void 0:m.size)===0){let l=(f=v.get(t))==null?void 0:f.get(a);t.removeEventListener(e,l,r),p==null||p.delete(a),(g=v.get(t))==null||g.delete(a),(p==null?void 0:p.size)===0&&(b.delete(t),v.delete(t))}}}var N=t=>Object.prototype.toString.call(t).slice(8,-1),It=t=>N(t)==="Object"&&"current"in t,Ot=t=>N(t)==="Function"?t():t,Rt=t=>N(t)==="Object"&&!!t.touches,Vt={pageX:0,pageY:0,clientX:0,clientY:0};function Dt(t,e="page"){let n=Rt(t)?t.touches[0]||t.changedTouches[0]||Vt:t;return{point:{x:n[`${e}X`],y:n[`${e}Y`]}}}function Nt(t,e,n,r){let o=It(t)?t.current:Ot(t);return Ct(o,e,n,r)}function k(t,e,n,r){var o;let a=(o=Yt(e))!=null?o:e;return Nt(t,a,Ft(n,e==="pointerdown"),r)}function Ft(t,e=!1){let n=r=>{t(r,Dt(r))};return e?Wt(n):n}function Wt(t){return e=>{var n;let r=(n=e.view)!=null?n:window,o=e instanceof r.MouseEvent;(!o||o&&e.button===0)&&t(e)}}var zt=()=>typeof window!="undefined"&&window.onpointerdown===null,Ht=()=>typeof window!="undefined"&&window.ontouchstart===null,_t=()=>typeof window!="undefined"&&window.onmousedown===null,jt={pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointercancel:"mousecancel",pointerover:"mouseover",pointerout:"mouseout",pointerenter:"mouseenter",pointerleave:"mouseleave"},Ut={pointerdown:"touchstart",pointermove:"touchmove",pointerup:"touchend",pointercancel:"touchcancel"};function Yt(t){return zt()?t:Ht()?Ut[t]:_t()?jt[t]:t}function X(t){var e;return(e=t==null?void 0:t.ownerDocument.defaultView)!=null?e:window}function B(t){var e;return(e=t.nativeEvent)!=null?e:t}function $t(t,e="input"){var n;let r=X(t)[e==="input"?"HTMLInputElement":"HTMLTextAreaElement"].prototype;return(n=Object.getOwnPropertyDescriptor(r,"value"))!=null?n:{}}function q(t,e){var n;let r=X(t);if(!(t instanceof r.HTMLInputElement))return;t.type="text",t.hidden=!0,(n=$t(t).set)==null||n.call(t,e);let o=new r.Event("input",{bubbles:!0});t.dispatchEvent(o),t.type="hidden",t.hidden=!1}var pe=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");var K={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",Home:"End",End:"Home"},Xt={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"};function G(t,e={}){var n;let{dir:r="ltr",orientation:o="horizontal"}=e,{key:a}=t;return a=(n=Xt[a])!=null?n:a,r==="rtl"&&o==="horizontal"&&a in K&&(a=K[a]),a}var Bt=new Set(["PageUp","PageDown"]),qt=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);function J(t){return t.ctrlKey||t.metaKey?.1:Bt.has(t.key)||t.shiftKey&&qt.has(t.key)?10:1}var E="default",F="",M=new WeakMap;function Kt({target:t,doc:e}={}){let n=e!=null?e:document;return $()?(E==="default"&&(F=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none"),E="disabled"):t&&(M.set(t,t.style.userSelect),t.style.userSelect="none"),()=>Gt({target:t,doc:n})}function Gt({target:t,doc:e}={}){let n=e!=null?e:document;if($()){if(E!=="disabled")return;E="restoring",setTimeout(()=>{V(()=>{E==="restoring"&&(n.documentElement.style.webkitUserSelect==="none"&&(n.documentElement.style.webkitUserSelect=F||""),F="",E="default")})},300)}else if(t&&M.has(t)){let r=M.get(t);t.style.userSelect==="none"&&(t.style.userSelect=r!=null?r:""),t.getAttribute("style")===""&&t.removeAttribute("style"),M.delete(t)}}function Z(t){let{onPointerMove:e,onPointerUp:n,ctx:r}=t,{doc:o=document,threshold:a=5}=r;return xt(k(o,"pointermove",(d,x)=>{let{point:u}=x;if(!(Math.sqrt(U(u.x,2)+U(u.y,2))<a)){if(At(d)&&Lt(d)){n();return}e(x,d)}},!1),k(o,"pointerup",n,!1),k(o,"pointercancel",n,!1),k(o,"contextmenu",n,!1),Kt({doc:o}))}var Jt=Math.pow;var Q=new Intl.NumberFormat("en-US",{style:"decimal"});function W(t){return parseFloat(Q.format(t))}function Zt(t,e){let n=y(t),r=Jt(10,e!=null?e:10);return n=Math.round(n*r)/r,e?n.toFixed(e):t.toString()}var T=(t,e)=>(y(t)-e.min)*100/(e.max-e.min),A=(t,e)=>e.min+(e.max-e.min)*y(t);function w(t,e){return Math.min(Math.max(y(t),e.min),e.max)}function Qt(t){var e,n;return(n=(e=Q.formatToParts(t).find(r=>r.type==="fraction"))==null?void 0:e.value.length)!=null?n:0}var tt=(t,e)=>W(y(t)+e),et=(t,e)=>W(y(t)-e),nt=(t,e)=>W(y(t)*e);function P(t,e){let n=y(t),r=Qt(e),o=Math.round(n/e)*e;return Zt(o,r)}function y(t){if(typeof t=="number")return t;let e=parseFloat(t.toString().replace(/[^\w.-]+/g,""));return Number.isNaN(e)?0:e}var L=(t,e)=>{let n={min:t[0],max:t[1]},r={min:e[0],max:e[1]};return o=>{if(n.min===n.max||r.min===r.max)return r.min;let a=(r.max-r.min)/(n.max-n.min);return r.min+a*(o-n.min)}};var ge=(()=>{let t=0;return()=>(t++,t.toString(36))})(),te=t=>Array.isArray(t),ee=t=>!(t==null||typeof t!="object"||te(t)),ne=t=>ee(t)&&"touches"in t;var re={pageX:0,pageY:0,clientX:0,clientY:0};function rt(t,e="page"){let n=ne(t)?t.touches[0]||t.changedTouches[0]||re:t;return{x:n[`${e}X`],y:n[`${e}Y`]}}function ot(t,e){let n=t.x-e.offsetLeft-e.clientLeft+e.scrollLeft,r=t.y-e.offsetTop-e.clientTop+e.scrollTop;return{point:{x:n,y:r},progress:{x:n/e.offsetWidth,y:r/e.offsetHeight}}}function oe(t){let{height:e}=t.thumbSize,n=L([t.min,t.max],[-e/2,e/2]);return parseFloat(n(t.value).toFixed(2))}function ie(t){let{width:e}=t.thumbSize;if(t.isRtl){let r=L([t.max,t.min],[-e*1.5,-e/2]);return-1*parseFloat(r(t.value).toFixed(2))}let n=L([t.min,t.max],[-e/2,e/2]);return parseFloat(n(t.value).toFixed(2))}function ae(t){let e=T(t.value,t),n=t.isVertical?oe(t):ie(t),r={position:"absolute",transform:"var(--slider-thumb-transform)","--slider-thumb-placement":`calc(${e}% - ${n}px)`};return t.isVertical?r.bottom="var(--slider-thumb-placement)":r[t.isRtl?"right":"left"]="var(--slider-thumb-placement)",r}function le(t){let e=T(t.value,t),n={position:"absolute"},r="0%",o=`${100-e}%`;if(t.origin==="center"){let a=e<50;r=a?`${e}%`:"50%",o=a?"50%":o}return t.isVertical?R(O({},n),{bottom:r,top:o}):R(O({},n),{[t.isRtl?"right":"left"]:r,[t.isRtl?"left":"right"]:o})}function ue(t){return{touchAction:"none",userSelect:"none","--slider-thumb-transform":t.isVertical?"translateY(50%)":"translateX(-50%)",position:"relative"}}var i={getDoc:t=>{var e;return(e=t.doc)!=null?e:document},getRootId:t=>`slider-${t.uid}`,getThumbId:t=>`slider-${t.uid}-thumb`,getControlId:t=>`slider-${t.uid}-control`,getInputId:t=>`slider-${t.uid}-input`,getOutputId:t=>`slider-${t.uid}-output`,getTrackId:t=>`slider--${t.uid}track`,getRangeId:t=>`slider-${t.uid}-range`,getLabelId:t=>`slider-${t.uid}-label`,getMarkerId:(t,e)=>`slider-${t.uid}-marker-${e}`,getThumbEl:t=>i.getDoc(t).getElementById(i.getThumbId(t)),getControlEl:t=>i.getDoc(t).getElementById(i.getControlId(t)),getInputEl:t=>i.getDoc(t).getElementById(i.getInputId(t)),getControlStyle:ue,getThumbStyle:ae,getRangeStyle:le,getTrackStyle:()=>({position:"relative"}),getValueFromPoint(t,e){let n=i.getControlEl(t);if(!n)return;let{progress:r}=ot(e,n),o;return t.isHorizontal?o=t.isRtl?1-r.x:r.x:o=1-r.y,o=w(o,{min:0,max:1}),parseFloat(P(A(o,t),t.step))},dispatchChangeEvent(t){let e=i.getInputEl(t);!e||q(e,t.value)},getMarkerStyle(t,e){let n={position:"absolute",pointerEvents:"none"};return t.isHorizontal?(e=t.isRtl?100-e:e,n.left=`${e}%`):n.bottom=`${e}%`,n}};function se(t){return{button:t,label:t,input:t,output:t,element:t}}var it=se(t=>t);var Te=(()=>{let t=0;return()=>(t++,t.toString(36))})();var at=t=>t.button===0;var lt=t=>t.ctrlKey||t.altKey||t.metaKey||t.shiftKey;function ut(t,e,n=it){var g,p;let r=t.context["aria-label"],o=t.context["aria-labelledby"],a=(p=(g=t.context).getAriaValueText)==null?void 0:p.call(g,t.context.value),d=t.matches("focus"),x=t.matches("dragging"),u=t.context.disabled,m=t.context.isInteractive,f=t.context.invalid;return{isFocused:d,isDragging:x,value:t.context.value,percent:T(t.context.value,t.context),setValue(l){e({type:"SET_VALUE",value:l})},getPercentValue(l){return A(l,t.context)},focus(){var l;(l=i.getThumbEl(t.context))==null||l.focus()},increment(){e("INCREMENT")},decrement(){e("DECREMENT")},rootProps:n.element({"data-part":"root","data-disabled":c(u),"data-orientation":t.context.orientation,id:i.getRootId(t.context),dir:t.context.dir}),labelProps:n.label({"data-part":"label","data-disabled":c(u),"data-invalid":c(f),id:i.getLabelId(t.context),htmlFor:i.getInputId(t.context),onClick(l){var s;!m||(l.preventDefault(),(s=i.getThumbEl(t.context))==null||s.focus())},style:{userSelect:"none"}}),thumbProps:n.element({"data-part":"thumb",id:i.getThumbId(t.context),"data-disabled":c(u),"data-orientation":t.context.orientation,"data-focus":c(d),draggable:!1,"aria-invalid":f||void 0,"data-invalid":c(f),"aria-disabled":u||void 0,"aria-label":r,"aria-labelledby":r?void 0:o!=null?o:i.getLabelId(t.context),"aria-orientation":t.context.orientation,"aria-valuemax":t.context.max,"aria-valuemin":t.context.min,"aria-valuenow":t.context.value,"aria-valuetext":a,role:"slider",tabIndex:u?void 0:0,onBlur(){!m||e("BLUR")},onFocus(){!m||e("FOCUS")},onKeyDown(l){if(!m)return;let s=nt(J(l),t.context.step),h=!0,I={ArrowUp(){e({type:"ARROW_UP",step:s}),h=t.context.isVertical},ArrowDown(){e({type:"ARROW_DOWN",step:s}),h=t.context.isVertical},ArrowLeft(){e({type:"ARROW_LEFT",step:s}),h=t.context.isHorizontal},ArrowRight(){e({type:"ARROW_RIGHT",step:s}),h=t.context.isHorizontal},PageUp(){e({type:"PAGE_UP",step:s})},PageDown(){e({type:"PAGE_DOWN",step:s})},Home(){e("HOME")},End(){e("END")}},ct=G(l,t.context),z=I[ct];!z||(z(l),h&&(l.preventDefault(),l.stopPropagation()))},style:i.getThumbStyle(t.context)}),inputProps:n.input({"data-part":"input",type:"hidden",defaultValue:t.context.value,name:t.context.name,id:i.getInputId(t.context)}),outputProps:n.output({"data-part":"output","data-disabled":c(u),"data-invalid":c(f),id:i.getOutputId(t.context),htmlFor:i.getInputId(t.context),"aria-live":"off"}),trackProps:n.element({"data-part":"track",id:i.getTrackId(t.context),"data-disabled":c(u),"data-invalid":c(f),"data-orientation":t.context.orientation,"data-focus":c(d),style:i.getTrackStyle()}),rangeProps:n.element({"data-part":"range",id:i.getRangeId(t.context),"data-invalid":c(f),"data-disabled":c(u),"data-orientation":t.context.orientation,style:i.getRangeStyle(t.context)}),controlProps:n.element({"data-part":"control",id:i.getControlId(t.context),"data-disabled":c(u),"data-invalid":c(f),"data-orientation":t.context.orientation,"data-focus":c(d),onPointerDown(l){if(!m)return;let s=B(l);if(!at(s)||lt(s))return;let h=rt(s);e({type:"POINTER_DOWN",point:h}),l.preventDefault(),l.stopPropagation()},style:i.getControlStyle(t.context)}),markerGroupProps:n.element({"data-part":"marker-group",role:"presentation","aria-hidden":!0,"data-orientation":t.context.orientation,style:{userSelect:"none",pointerEvents:"none",position:"relative"}}),getMarkerProps({value:l}){let s=T(l,t.context),h=i.getMarkerStyle(t.context,s),I=l>t.context.value?"over-value":l<t.context.value?"under-value":"at-value";return n.element({"data-part":"marker","data-orientation":t.context.orientation,id:i.getMarkerId(t.context,l),"data-value":l,"data-disabled":c(u),"data-state":I,style:h})}}}var C=require("@zag-js/core");var st=(0,C.createMachine)({id:"slider-machine",initial:"unknown",context:{thumbSize:{width:0,height:0},uid:"",disabled:!1,threshold:5,dir:"ltr",origin:"start",orientation:"horizontal",value:0,step:1,min:0,max:100},computed:{isHorizontal:t=>t.orientation==="horizontal",isVertical:t=>t.orientation==="vertical",isRtl:t=>t.orientation==="horizontal"&&t.dir==="rtl",isInteractive:t=>!(t.disabled||t.readonly)},watch:{value:["invokeOnChange","dispatchChangeEvent"]},states:{unknown:{on:{SETUP:{target:"idle",actions:["setupDocument","setThumbSize"]}}},idle:{on:{POINTER_DOWN:{target:"dragging",actions:["setPointerValue","invokeOnChangeStart","focusThumb"]},FOCUS:"focus"}},focus:{entry:"focusThumb",on:{POINTER_DOWN:{target:"dragging",actions:["setPointerValue","invokeOnChangeStart","focusThumb"]},ARROW_LEFT:{guard:"isHorizontal",actions:["decrement"]},ARROW_RIGHT:{guard:"isHorizontal",actions:["increment"]},ARROW_UP:{guard:"isVertical",actions:["increment"]},ARROW_DOWN:{guard:"isVertical",actions:["decrement"]},PAGE_UP:{actions:["increment"]},PAGE_DOWN:{actions:["decrement"]},HOME:{actions:["setToMin"]},END:{actions:["setToMax"]},BLUR:"idle"}},dragging:{entry:"focusThumb",activities:"trackPointerMove",on:{POINTER_UP:{target:"focus",actions:"invokeOnChangeEnd"},POINTER_MOVE:{actions:"setPointerValue"}}}}},{guards:{isHorizontal:t=>t.isHorizontal,isVertical:t=>t.isVertical},activities:{trackPointerMove(t,e,{send:n}){return Z({ctx:t,onPointerMove(r){n({type:"POINTER_MOVE",point:r.point})},onPointerUp(){n("POINTER_UP")}})}},actions:{setupDocument(t,e){e.doc&&(t.doc=(0,C.ref)(e.doc)),t.uid=e.id},invokeOnChangeStart(t){var e;(e=t.onChangeStart)==null||e.call(t,t.value)},invokeOnChangeEnd(t){var e;(e=t.onChangeEnd)==null||e.call(t,t.value)},invokeOnChange(t){var e;(e=t.onChange)==null||e.call(t,t.value)},dispatchChangeEvent(t){i.dispatchChangeEvent(t)},setThumbSize(t){Y(()=>{let e=i.getThumbEl(t);!e||(t.thumbSize.width=e.offsetWidth,t.thumbSize.height=e.offsetHeight)})},setPointerValue(t,e){let n=i.getValueFromPoint(t,e.point);n!=null&&(t.value=w(n,t))},focusThumb(t){V(()=>{var e;return(e=i.getThumbEl(t))==null?void 0:e.focus()})},decrement(t,e){var r;let n=et(t.value,(r=e.step)!=null?r:t.step);n=parseFloat(P(n,t.step)),t.value=w(n,t)},increment(t,e){var r;let n=tt(t.value,(r=e.step)!=null?r:t.step);n=parseFloat(P(n,t.step)),t.value=w(n,t)},setToMin(t){t.value=t.min},setToMax(t){t.value=t.max},setValue(t,e){t.value=w(e.value,t)}}});module.exports=bt(ce); | ||
var k=Object.defineProperty,ht=Object.defineProperties,vt=Object.getOwnPropertyDescriptor,gt=Object.getOwnPropertyDescriptors,yt=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable;var U=(t,e,n)=>e in t?k(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,O=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&U(t,n,e[n]);if(_)for(var n of _(e))bt.call(e,n)&&U(t,n,e[n]);return t},V=(t,e)=>ht(t,gt(e)),wt=t=>k(t,"__esModule",{value:!0});var xt=(t,e)=>{for(var n in e)k(t,n,{get:e[n],enumerable:!0})},Et=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of yt(e))!j.call(t,o)&&(n||o!=="default")&&k(t,o,{get:()=>e[o],enumerable:!(r=vt(e,o))||r.enumerable});return t};var Tt=(t=>(e,n)=>t&&t.get(e)||(n=Et(wt({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var he={};xt(he,{connect:()=>ft,machine:()=>pt,unstable__dom:()=>a});var Y=Math.pow,d=t=>t?"":void 0;function P(t){let e=new Set;function n(r){let o=globalThis.requestAnimationFrame(r);e.add(()=>globalThis.cancelAnimationFrame(o))}return n(()=>n(t)),function(){e.forEach(function(r){r()})}}function $(t){let e=globalThis.requestAnimationFrame(t);return function(){globalThis.cancelAnimationFrame(e)}}var Pt=()=>{},kt=(...t)=>e=>t.reduce((n,r)=>r(n),e),ge=(()=>{let t=0;return()=>(t++,t.toString(36))})(),N=t=>St()&&t.test(navigator.platform),St=()=>typeof window!="undefined",Mt=()=>N(/^Mac/),At=()=>N(/^iPhone/),Ct=()=>N(/^iPad/)||Mt()&&navigator.maxTouchPoints>1,X=()=>At()||Ct(),Lt=t=>Array.isArray(t),It=t=>!(t==null||typeof t!="object"||Lt(t)),Rt=t=>It(t)&&"button"in t,Ot=t=>t.button===0,x=new Map,b=new Map;function Vt(t,e,n,r){var o;if(!t)return Pt;let i=JSON.stringify({type:e,options:r}),s=x.get(t);if(x.has(t))(s==null?void 0:s.has(i))?(o=s==null?void 0:s.get(i))==null||o.add(n):s==null||s.set(i,new Set([n]));else{let l=new Map([[i,new Set([n])]]);x.set(t,l)}function y(l){var m,f;function v(p){var u;let c=x.get(l);(u=c==null?void 0:c.get(i))==null||u.forEach(h=>h(p))}if(!(b==null?void 0:b.has(l))){b.set(l,new Map([[i,v]])),l.addEventListener(e,v,r);return}((m=b==null?void 0:b.get(l))==null?void 0:m.has(i))||((f=b.get(l))==null||f.set(i,v),l.addEventListener(e,v,r))}return y(t),function(){var l,m,f,v;if(!x.has(t))return;let p=x.get(t);if((l=p==null?void 0:p.get(i))==null||l.delete(n),((m=p==null?void 0:p.get(i))==null?void 0:m.size)===0){let u=(f=b.get(t))==null?void 0:f.get(i);t.removeEventListener(e,u,r),p==null||p.delete(i),(v=b.get(t))==null||v.delete(i),(p==null?void 0:p.size)===0&&(x.delete(t),b.delete(t))}}}var F=t=>Object.prototype.toString.call(t).slice(8,-1),Nt=t=>F(t)==="Object"&&"current"in t,Ft=t=>F(t)==="Function"?t():t,Dt=t=>F(t)==="Object"&&!!t.touches,Wt={pageX:0,pageY:0,clientX:0,clientY:0};function Ht(t,e="page"){let n=Dt(t)?t.touches[0]||t.changedTouches[0]||Wt:t;return{point:{x:n[`${e}X`],y:n[`${e}Y`]}}}function zt(t,e,n,r){let o=Nt(t)?t.current:Ft(t);return Vt(o,e,n,r)}function S(t,e,n,r){var o;let i=(o=qt(e))!=null?o:e;return zt(t,i,_t(n,e==="pointerdown"),r)}function _t(t,e=!1){let n=r=>{t(r,Ht(r))};return e?jt(n):n}function jt(t){return e=>{var n;let r=(n=e.view)!=null?n:window,o=e instanceof r.MouseEvent;(!o||o&&e.button===0)&&t(e)}}var Ut=()=>typeof window!="undefined"&&window.onpointerdown===null,Yt=()=>typeof window!="undefined"&&window.ontouchstart===null,$t=()=>typeof window!="undefined"&&window.onmousedown===null,Xt={pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointercancel:"mousecancel",pointerover:"mouseover",pointerout:"mouseout",pointerenter:"mouseenter",pointerleave:"mouseleave"},Bt={pointerdown:"touchstart",pointermove:"touchmove",pointerup:"touchend",pointercancel:"touchcancel"};function qt(t){return Ut()?t:Yt()?Bt[t]:$t()?Xt[t]:t}function B(t){var e;return(e=t==null?void 0:t.ownerDocument.defaultView)!=null?e:window}function q(t){var e;return(e=t.nativeEvent)!=null?e:t}function K(t,e){var n;let{type:r,property:o}=e,i=B(t)[r==="input"?"HTMLInputElement":"HTMLTextAreaElement"].prototype;return(n=Object.getOwnPropertyDescriptor(i,o))!=null?n:{}}function G(t,e){var n;let r=B(t);if(!(t instanceof r.HTMLInputElement))return;(n=K(t,{type:"input",property:"value"}).set)==null||n.call(t,e);let o=new r.Event("input",{bubbles:!0});t.dispatchEvent(o)}function Z(t,e){let{fn:n,property:r,type:o}=e;if(!n||!t)return;let{get:i,set:s}=K(t,{property:r,type:o}),y=!0;return Object.defineProperty(t,r,{get(){return i==null?void 0:i.call(this)},set(l){return y&&n(l),s==null?void 0:s.call(this,l)}}),function(){y=!1}}var ye=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function Kt(t){return Gt(t)?t.form:t.closest("form")}function Gt(t){return["textarea","input","select","button"].includes(t.localName)}function J(t,e){if(!t)return;let n=Kt(t);return n==null||n.addEventListener("reset",e,{passive:!0}),()=>{n==null||n.removeEventListener("reset",e)}}var Q={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",Home:"End",End:"Home"},Zt={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"};function tt(t,e={}){var n;let{dir:r="ltr",orientation:o="horizontal"}=e,{key:i}=t;return i=(n=Zt[i])!=null?n:i,r==="rtl"&&o==="horizontal"&&i in Q&&(i=Q[i]),i}var Jt=new Set(["PageUp","PageDown"]),Qt=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);function et(t){return t.ctrlKey||t.metaKey?.1:Jt.has(t.key)||t.shiftKey&&Qt.has(t.key)?10:1}var E="default",D="",M=new WeakMap;function te({target:t,doc:e}={}){let n=e!=null?e:document;return X()?(E==="default"&&(D=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none"),E="disabled"):t&&(M.set(t,t.style.userSelect),t.style.userSelect="none"),()=>ee({target:t,doc:n})}function ee({target:t,doc:e}={}){let n=e!=null?e:document;if(X()){if(E!=="disabled")return;E="restoring",setTimeout(()=>{P(()=>{E==="restoring"&&(n.documentElement.style.webkitUserSelect==="none"&&(n.documentElement.style.webkitUserSelect=D||""),D="",E="default")})},300)}else if(t&&M.has(t)){let r=M.get(t);t.style.userSelect==="none"&&(t.style.userSelect=r!=null?r:""),t.getAttribute("style")===""&&t.removeAttribute("style"),M.delete(t)}}function nt(t){let{onPointerMove:e,onPointerUp:n,ctx:r}=t,{doc:o=document,threshold:i=5}=r;return kt(S(o,"pointermove",(s,y)=>{let{point:l}=y;if(!(Math.sqrt(Y(l.x,2)+Y(l.y,2))<i)){if(Rt(s)&&Ot(s)){n();return}e(y,s)}},!1),S(o,"pointerup",n,!1),S(o,"pointercancel",n,!1),S(o,"contextmenu",n,!1),te({doc:o}))}var ne=Math.pow;var rt=new Intl.NumberFormat("en-US",{style:"decimal"});function W(t){return parseFloat(rt.format(t))}function re(t,e){let n=w(t),r=ne(10,e!=null?e:10);return n=Math.round(n*r)/r,e?n.toFixed(e):t.toString()}var T=(t,e)=>(w(t)-e.min)*100/(e.max-e.min),A=(t,e)=>e.min+(e.max-e.min)*w(t);function C(t,e){return Math.min(Math.max(w(t),e.min),e.max)}function oe(t){var e,n;return(n=(e=rt.formatToParts(t).find(r=>r.type==="fraction"))==null?void 0:e.value.length)!=null?n:0}var ot=(t,e)=>W(w(t)+e),it=(t,e)=>W(w(t)-e),at=(t,e)=>W(w(t)*e);function H(t,e){let n=w(t),r=oe(e),o=Math.round(n/e)*e;return re(o,r)}function w(t){if(typeof t=="number")return t;let e=parseFloat(t.toString().replace(/[^\w.-]+/g,""));return Number.isNaN(e)?0:e}var L=(t,e)=>{let n={min:t[0],max:t[1]},r={min:e[0],max:e[1]};return o=>{if(n.min===n.max||r.min===r.max)return r.min;let i=(r.max-r.min)/(n.max-n.min);return r.min+i*(o-n.min)}};var xe=(()=>{let t=0;return()=>(t++,t.toString(36))})(),ie=t=>Array.isArray(t),ae=t=>!(t==null||typeof t!="object"||ie(t)),le=t=>ae(t)&&"touches"in t;var ue={pageX:0,pageY:0,clientX:0,clientY:0};function lt(t,e="page"){let n=le(t)?t.touches[0]||t.changedTouches[0]||ue:t;return{x:n[`${e}X`],y:n[`${e}Y`]}}function ut(t,e){let n=t.x-e.offsetLeft-e.clientLeft+e.scrollLeft,r=t.y-e.offsetTop-e.clientTop+e.scrollTop;return{point:{x:n,y:r},progress:{x:n/e.offsetWidth,y:r/e.offsetHeight}}}var g={fromPercent(t,e){return e=C(e,{min:0,max:1}),parseFloat(H(A(e,t),t.step))},clamp(t,e){return C(e,t)},convert(t,e){return C(parseFloat(H(e,t.step)),t)},decrement(t,e){let n=it(t.value,e!=null?e:t.step);return g.convert(t,n)},increment(t,e){let n=ot(t.value,e!=null?e:t.step);return g.convert(t,n)}};function se(t){var r;let{height:e=0}=(r=t.thumbSize)!=null?r:{},n=L([t.min,t.max],[-e/2,e/2]);return parseFloat(n(t.value).toFixed(2))}function ce(t){var r;let{width:e=0}=(r=t.thumbSize)!=null?r:{};if(t.isRtl){let o=L([t.max,t.min],[-e*1.5,-e/2]);return-1*parseFloat(o(t.value).toFixed(2))}let n=L([t.min,t.max],[-e/2,e/2]);return parseFloat(n(t.value).toFixed(2))}function de(t){let e=T(t.value,t),n=t.isVertical?se(t):ce(t),r={visibility:t.hasMeasuredThumbSize?"visible":"hidden",position:"absolute",transform:"var(--slider-thumb-transform)","--slider-thumb-placement":`calc(${e}% - ${n}px)`};return t.isVertical?r.bottom="var(--slider-thumb-placement)":r[t.isRtl?"right":"left"]="var(--slider-thumb-placement)",r}function fe(t){let e=T(t.value,t),n={position:"absolute"},r="0%",o=`${100-e}%`;if(t.origin==="center"){let i=e<50;r=i?`${e}%`:"50%",o=i?"50%":o}return t.isVertical?V(O({},n),{bottom:r,top:o}):V(O({},n),{[t.isRtl?"right":"left"]:r,[t.isRtl?"left":"right"]:o})}function pe(t){return{touchAction:"none",userSelect:"none","--slider-thumb-transform":t.isVertical?"translateY(50%)":"translateX(-50%)",position:"relative"}}var a={getDoc:t=>{var e;return(e=t.doc)!=null?e:document},getRootId:t=>`slider-${t.uid}`,getThumbId:t=>`slider-${t.uid}-thumb`,getControlId:t=>`slider-${t.uid}-control`,getInputId:t=>`slider-${t.uid}-input`,getOutputId:t=>`slider-${t.uid}-output`,getTrackId:t=>`slider--${t.uid}track`,getRangeId:t=>`slider-${t.uid}-range`,getLabelId:t=>`slider-${t.uid}-label`,getMarkerId:(t,e)=>`slider-${t.uid}-marker-${e}`,getThumbEl:t=>a.getDoc(t).getElementById(a.getThumbId(t)),getControlEl:t=>a.getDoc(t).getElementById(a.getControlId(t)),getInputEl:t=>a.getDoc(t).getElementById(a.getInputId(t)),getControlStyle:pe,getThumbStyle:de,getRangeStyle:fe,getValueFromPoint(t,e){let n=a.getControlEl(t);if(!n)return;let{progress:r}=ut(e,n),o;return t.isHorizontal?o=t.isRtl?1-r.x:r.x:o=1-r.y,g.fromPercent(t,o)},dispatchChangeEvent(t){let e=a.getInputEl(t);!e||G(e,t.value)},getMarkerStyle(t,e){let n={position:"absolute",pointerEvents:"none"};return t.isHorizontal?(e=t.isRtl?100-e:e,n.left=`${e}%`):n.bottom=`${e}%`,n}};function me(t){return{button:t,label:t,input:t,output:t,element:t}}var st=me(t=>t);var Ie=(()=>{let t=0;return()=>(t++,t.toString(36))})();var ct=t=>t.button===0;var dt=t=>t.ctrlKey||t.altKey||t.metaKey||t.shiftKey;function ft(t,e,n=st){var v,p;let r=t.context["aria-label"],o=t.context["aria-labelledby"],i=(p=(v=t.context).getAriaValueText)==null?void 0:p.call(v,t.context.value),s=t.matches("focus"),y=t.matches("dragging"),l=t.context.disabled,m=t.context.isInteractive,f=t.context.invalid;return{isFocused:s,isDragging:y,value:t.context.value,percent:T(t.context.value,t.context),setValue(u){e({type:"SET_VALUE",value:u})},getPercentValue(u){return A(u,t.context)},focus(){var u;(u=a.getThumbEl(t.context))==null||u.focus()},increment(){e("INCREMENT")},decrement(){e("DECREMENT")},rootProps:n.element({"data-part":"root","data-disabled":d(l),"data-orientation":t.context.orientation,id:a.getRootId(t.context),dir:t.context.dir}),labelProps:n.label({"data-part":"label","data-disabled":d(l),"data-invalid":d(f),id:a.getLabelId(t.context),htmlFor:a.getInputId(t.context),onClick(u){var c;!m||(u.preventDefault(),(c=a.getThumbEl(t.context))==null||c.focus())},style:{userSelect:"none"}}),thumbProps:n.element({"data-part":"thumb",id:a.getThumbId(t.context),"data-disabled":d(l),"data-orientation":t.context.orientation,"data-focus":d(s),draggable:!1,"aria-invalid":f||void 0,"data-invalid":d(f),"aria-disabled":l||void 0,"aria-label":r,"aria-labelledby":r?void 0:o!=null?o:a.getLabelId(t.context),"aria-orientation":t.context.orientation,"aria-valuemax":t.context.max,"aria-valuemin":t.context.min,"aria-valuenow":t.context.value,"aria-valuetext":i,role:"slider",tabIndex:l?void 0:0,onBlur(){!m||e("BLUR")},onFocus(){!m||e("FOCUS")},onKeyDown(u){if(!m)return;let c=at(et(u),t.context.step),h=!0,R={ArrowUp(){e({type:"ARROW_UP",step:c}),h=t.context.isVertical},ArrowDown(){e({type:"ARROW_DOWN",step:c}),h=t.context.isVertical},ArrowLeft(){e({type:"ARROW_LEFT",step:c}),h=t.context.isHorizontal},ArrowRight(){e({type:"ARROW_RIGHT",step:c}),h=t.context.isHorizontal},PageUp(){e({type:"PAGE_UP",step:c})},PageDown(){e({type:"PAGE_DOWN",step:c})},Home(){e("HOME")},End(){e("END")}},mt=tt(u,t.context),z=R[mt];!z||(z(u),h&&(u.preventDefault(),u.stopPropagation()))},style:a.getThumbStyle(t.context)}),inputProps:n.input({"data-part":"input",type:"text",defaultValue:t.context.value,name:t.context.name,id:a.getInputId(t.context),hidden:!0}),outputProps:n.output({"data-part":"output","data-disabled":d(l),"data-invalid":d(f),id:a.getOutputId(t.context),htmlFor:a.getInputId(t.context),"aria-live":"off"}),trackProps:n.element({"data-part":"track",id:a.getTrackId(t.context),"data-disabled":d(l),"data-invalid":d(f),"data-orientation":t.context.orientation,"data-focus":d(s),style:{position:"relative"}}),rangeProps:n.element({"data-part":"range",id:a.getRangeId(t.context),"data-invalid":d(f),"data-disabled":d(l),"data-orientation":t.context.orientation,style:a.getRangeStyle(t.context)}),controlProps:n.element({"data-part":"control",id:a.getControlId(t.context),"data-disabled":d(l),"data-invalid":d(f),"data-orientation":t.context.orientation,"data-focus":d(s),onPointerDown(u){if(!m)return;let c=q(u);if(!ct(c)||dt(c))return;let h=lt(c);e({type:"POINTER_DOWN",point:h}),u.preventDefault(),u.stopPropagation()},style:a.getControlStyle(t.context)}),markerGroupProps:n.element({"data-part":"marker-group",role:"presentation","aria-hidden":!0,"data-orientation":t.context.orientation,style:{userSelect:"none",pointerEvents:"none",position:"relative"}}),getMarkerProps({value:u}){let c=T(u,t.context),h=a.getMarkerStyle(t.context,c),R=u>t.context.value?"over-value":u<t.context.value?"under-value":"at-value";return n.element({"data-part":"marker","data-orientation":t.context.orientation,id:a.getMarkerId(t.context,u),"data-value":u,"data-disabled":d(l),"data-state":R,style:h})}}}var I=require("@zag-js/core");var pt=(0,I.createMachine)({id:"slider-machine",initial:"unknown",context:{thumbSize:null,uid:"",disabled:!1,threshold:5,dir:"ltr",origin:"start",orientation:"horizontal",initialValue:null,value:0,step:1,min:0,max:100},computed:{isHorizontal:t=>t.orientation==="horizontal",isVertical:t=>t.orientation==="vertical",isRtl:t=>t.orientation==="horizontal"&&t.dir==="rtl",isInteractive:t=>!(t.disabled||t.readonly),hasMeasuredThumbSize:t=>t.thumbSize!==null},watch:{value:["invokeOnChange","dispatchChangeEvent"]},activities:["trackFormReset","trackScriptedUpdate"],on:{SET_VALUE:{actions:"setValue"},INCREMENT:{actions:"increment"},DECREMENT:{actions:"decrement"}},states:{unknown:{on:{SETUP:{target:"idle",actions:["setupDocument","setThumbSize","checkValue"]}}},idle:{on:{POINTER_DOWN:{target:"dragging",actions:["setPointerValue","invokeOnChangeStart","focusThumb"]},FOCUS:"focus"}},focus:{entry:"focusThumb",on:{POINTER_DOWN:{target:"dragging",actions:["setPointerValue","invokeOnChangeStart","focusThumb"]},ARROW_LEFT:{guard:"isHorizontal",actions:"decrement"},ARROW_RIGHT:{guard:"isHorizontal",actions:"increment"},ARROW_UP:{guard:"isVertical",actions:"increment"},ARROW_DOWN:{guard:"isVertical",actions:"decrement"},PAGE_UP:{actions:"increment"},PAGE_DOWN:{actions:"decrement"},HOME:{actions:"setToMin"},END:{actions:"setToMax"},BLUR:"idle"}},dragging:{entry:"focusThumb",activities:"trackPointerMove",on:{POINTER_UP:{target:"focus",actions:"invokeOnChangeEnd"},POINTER_MOVE:{actions:"setPointerValue"}}}}},{guards:{isHorizontal:t=>t.isHorizontal,isVertical:t=>t.isVertical},activities:{trackScriptedUpdate(t,e,{send:n}){let r;return P(()=>{let o=a.getInputEl(t);!o||(r=Z(o,{type:"input",property:"value",fn(i){n({type:"SET_VALUE",value:parseFloat(i)})}}))}),()=>r==null?void 0:r()},trackFormReset(t){let e;return P(()=>{let n=a.getInputEl(t);!n||(e=J(n,()=>{t.initialValue!=null&&(t.value=t.initialValue)}))}),e},trackPointerMove(t,e,{send:n}){return nt({ctx:t,onPointerMove(r){n({type:"POINTER_MOVE",point:r.point})},onPointerUp(){n("POINTER_UP")}})}},actions:{setupDocument(t,e){e.doc&&(t.doc=(0,I.ref)(e.doc)),t.uid=e.id},checkValue(t){let e=g.convert(t,t.value);Object.assign(t,{value:e,initialValue:e})},invokeOnChangeStart(t){var e;(e=t.onChangeStart)==null||e.call(t,t.value)},invokeOnChangeEnd(t){var e;(e=t.onChangeEnd)==null||e.call(t,t.value)},invokeOnChange(t){var e;(e=t.onChange)==null||e.call(t,t.value)},dispatchChangeEvent(t){a.dispatchChangeEvent(t)},setThumbSize(t){$(()=>{let e=a.getThumbEl(t);!e||(t.thumbSize={width:e.offsetWidth,height:e.offsetHeight})})},setPointerValue(t,e){let n=a.getValueFromPoint(t,e.point);n!=null&&(t.value=g.clamp(t,n))},focusThumb(t){P(()=>{var e;return(e=a.getThumbEl(t))==null?void 0:e.focus()})},decrement(t,e){t.value=g.decrement(t,e.step)},increment(t,e){t.value=g.increment(t,e.step)},setToMin(t){t.value=t.min},setToMax(t){t.value=t.max},setValue(t,e){t.value=g.convert(t,e.value)}}});module.exports=Tt(he); | ||
//# sourceMappingURL=index.js.map |
import type { Point } from "@zag-js/rect-utils"; | ||
import type { Style } from "@zag-js/types"; | ||
import type { SharedContext, MachineContext as Ctx } from "./slider.types"; | ||
import type { MachineContext as Ctx, SharedContext } from "./slider.types"; | ||
declare function getThumbStyle(ctx: SharedContext): Style; | ||
@@ -20,7 +20,6 @@ declare function getRangeStyle(ctx: Ctx): Style; | ||
getControlEl: (ctx: Ctx) => HTMLElement; | ||
getInputEl: (ctx: Ctx) => HTMLElement; | ||
getInputEl: (ctx: Ctx) => HTMLInputElement; | ||
getControlStyle: typeof getControlStyle; | ||
getThumbStyle: typeof getThumbStyle; | ||
getRangeStyle: typeof getRangeStyle; | ||
getTrackStyle: () => Style; | ||
getValueFromPoint(ctx: Ctx, point: Point): number | undefined; | ||
@@ -27,0 +26,0 @@ dispatchChangeEvent(ctx: Ctx): void; |
@@ -8,2 +8,7 @@ import { Context } from "@zag-js/types"; | ||
/** | ||
* The value of the slider when it was initially rendered. | ||
* Used when the `form.reset(...)` is called. | ||
*/ | ||
initialValue: number | null; | ||
/** | ||
* The name associated with the slider (when used in a form) | ||
@@ -87,4 +92,8 @@ */ | ||
height: number; | ||
}; | ||
} | null; | ||
/** | ||
* @internal Whether the thumb size has been measured | ||
*/ | ||
readonly hasMeasuredThumbSize: boolean; | ||
/** | ||
* @computed Whether the slider is horizontal | ||
@@ -114,4 +123,5 @@ */ | ||
height: number; | ||
}; | ||
} | null; | ||
orientation?: "horizontal" | "vertical"; | ||
readonly hasMeasuredThumbSize: boolean; | ||
}; | ||
@@ -118,0 +128,0 @@ export declare type MachineState = { |
{ | ||
"name": "@zag-js/slider", | ||
"version": "0.0.0-dev-20220407084218", | ||
"version": "0.0.0-dev-20220408111010", | ||
"description": "Core logic for the slider widget implemented as a state machine", | ||
@@ -32,9 +32,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/core": "^0.0.0-dev-20220407084218", | ||
"@zag-js/dom-utils": "^0.0.0-dev-20220407084218", | ||
"@zag-js/number-utils": "^0.0.0-dev-20220407084218", | ||
"@zag-js/rect-utils": "^0.0.0-dev-20220407084218", | ||
"@zag-js/types": "^0.0.0-dev-20220407084218", | ||
"@zag-js/utils": "^0.0.0-dev-20220407084218" | ||
"@zag-js/core": "^0.0.0-dev-20220408111010", | ||
"@zag-js/dom-utils": "^0.0.0-dev-20220408111010", | ||
"@zag-js/number-utils": "^0.0.0-dev-20220408111010", | ||
"@zag-js/rect-utils": "^0.0.0-dev-20220408111010", | ||
"@zag-js/types": "^0.0.0-dev-20220408111010", | ||
"@zag-js/utils": "^0.0.0-dev-20220408111010" | ||
} | ||
} |
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
269771
12
332