Slider-0c64af90-1694078809672.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import{cq as We,r as x,b0 as qe,cP as M,cm as n,cS as m,cR as j,cQ as ue,dx as Ge,dy as Qe,d as Ze,cT as Je,cU as ge,cX as eo,L as w,bA as oo,cW as to,y as he,o as ao,c$ as ve,cZ as no,cY as J,aG as v,d0 as ro,d1 as lo,cI as io,d3 as so,T as co,dz as U,dA as O,E as Z,d7 as fe}from"./index-ce8959eb-1694078809672.js";const uo={railHeight:"4px",railWidthVertical:"4px",handleSize:"18px",dotHeight:"8px",dotWidth:"8px",dotBorderRadius:"4px"},ho=a=>{const l="rgba(0, 0, 0, .85)",y="0 2px 8px 0 rgba(0, 0, 0, 0.12)",{railColor:f,primaryColor:s,baseColor:d,cardColor:z,modalColor:R,popoverColor:L,borderRadius:_,fontSize:B,opacityDisabled:$}=a;return Object.assign(Object.assign({},uo),{fontSize:B,markFontSize:B,railColor:f,railColorHover:f,fillColor:s,fillColorHover:s,opacityDisabled:$,handleColor:"#FFF",dotColor:z,dotColorModal:R,dotColorPopover:L,handleBoxShadow:"0 1px 4px 0 rgba(0, 0, 0, 0.3), inset 0 0 1px 0 rgba(0, 0, 0, 0.05)",handleBoxShadowHover:"0 1px 4px 0 rgba(0, 0, 0, 0.3), inset 0 0 1px 0 rgba(0, 0, 0, 0.05)",handleBoxShadowActive:"0 1px 4px 0 rgba(0, 0, 0, 0.3), inset 0 0 1px 0 rgba(0, 0, 0, 0.05)",handleBoxShadowFocus:"0 1px 4px 0 rgba(0, 0, 0, 0.3), inset 0 0 1px 0 rgba(0, 0, 0, 0.05)",indicatorColor:l,indicatorBoxShadow:y,indicatorTextColor:d,indicatorBorderRadius:_,dotBorder:`2px solid ${f}`,dotBorderActive:`2px solid ${s}`,dotBoxShadow:""})},vo={name:"Slider",common:We,self:ho},fo=vo;function me(a){return window.TouchEvent&&a instanceof window.TouchEvent}function be(){const a=x(new Map),l=y=>f=>{a.value.set(y,f)};return qe(()=>{a.value.clear()}),[a,l]}const mo=M([n("slider",`
  2. display: block;
  3. padding: calc((var(--n-handle-size) - var(--n-rail-height)) / 2) 0;
  4. position: relative;
  5. z-index: 0;
  6. width: 100%;
  7. cursor: pointer;
  8. user-select: none;
  9. -webkit-user-select: none;
  10. `,[m("reverse",[n("slider-handles",[n("slider-handle-wrapper",`
  11. transform: translate(50%, -50%);
  12. `)]),n("slider-dots",[n("slider-dot",`
  13. transform: translateX(50%, -50%);
  14. `)]),m("vertical",[n("slider-handles",[n("slider-handle-wrapper",`
  15. transform: translate(-50%, -50%);
  16. `)]),n("slider-marks",[n("slider-mark",`
  17. transform: translateY(calc(-50% + var(--n-dot-height) / 2));
  18. `)]),n("slider-dots",[n("slider-dot",`
  19. transform: translateX(-50%) translateY(0);
  20. `)])])]),m("vertical",`
  21. padding: 0 calc((var(--n-handle-size) - var(--n-rail-height)) / 2);
  22. width: var(--n-rail-width-vertical);
  23. height: 100%;
  24. `,[n("slider-handles",`
  25. top: calc(var(--n-handle-size) / 2);
  26. right: 0;
  27. bottom: calc(var(--n-handle-size) / 2);
  28. left: 0;
  29. `,[n("slider-handle-wrapper",`
  30. top: unset;
  31. left: 50%;
  32. transform: translate(-50%, 50%);
  33. `)]),n("slider-rail",`
  34. height: 100%;
  35. `,[j("fill",`
  36. top: unset;
  37. right: 0;
  38. bottom: unset;
  39. left: 0;
  40. `)]),m("with-mark",`
  41. width: var(--n-rail-width-vertical);
  42. margin: 0 32px 0 8px;
  43. `),n("slider-marks",`
  44. top: calc(var(--n-handle-size) / 2);
  45. right: unset;
  46. bottom: calc(var(--n-handle-size) / 2);
  47. left: 22px;
  48. font-size: var(--n-mark-font-size);
  49. `,[n("slider-mark",`
  50. transform: translateY(50%);
  51. white-space: nowrap;
  52. `)]),n("slider-dots",`
  53. top: calc(var(--n-handle-size) / 2);
  54. right: unset;
  55. bottom: calc(var(--n-handle-size) / 2);
  56. left: 50%;
  57. `,[n("slider-dot",`
  58. transform: translateX(-50%) translateY(50%);
  59. `)])]),m("disabled",`
  60. cursor: not-allowed;
  61. opacity: var(--n-opacity-disabled);
  62. `,[n("slider-handle",`
  63. cursor: not-allowed;
  64. `)]),m("with-mark",`
  65. width: 100%;
  66. margin: 8px 0 32px 0;
  67. `),M("&:hover",[n("slider-rail",{backgroundColor:"var(--n-rail-color-hover)"},[j("fill",{backgroundColor:"var(--n-fill-color-hover)"})]),n("slider-handle",{boxShadow:"var(--n-handle-box-shadow-hover)"})]),m("active",[n("slider-rail",{backgroundColor:"var(--n-rail-color-hover)"},[j("fill",{backgroundColor:"var(--n-fill-color-hover)"})]),n("slider-handle",{boxShadow:"var(--n-handle-box-shadow-hover)"})]),n("slider-marks",`
  68. position: absolute;
  69. top: 18px;
  70. left: calc(var(--n-handle-size) / 2);
  71. right: calc(var(--n-handle-size) / 2);
  72. `,[n("slider-mark",`
  73. position: absolute;
  74. transform: translateX(-50%);
  75. white-space: nowrap;
  76. `)]),n("slider-rail",`
  77. width: 100%;
  78. position: relative;
  79. height: var(--n-rail-height);
  80. background-color: var(--n-rail-color);
  81. transition: background-color .3s var(--n-bezier);
  82. border-radius: calc(var(--n-rail-height) / 2);
  83. `,[j("fill",`
  84. position: absolute;
  85. top: 0;
  86. bottom: 0;
  87. border-radius: calc(var(--n-rail-height) / 2);
  88. transition: background-color .3s var(--n-bezier);
  89. background-color: var(--n-fill-color);
  90. `)]),n("slider-handles",`
  91. position: absolute;
  92. top: 0;
  93. right: calc(var(--n-handle-size) / 2);
  94. bottom: 0;
  95. left: calc(var(--n-handle-size) / 2);
  96. `,[n("slider-handle-wrapper",`
  97. outline: none;
  98. position: absolute;
  99. top: 50%;
  100. transform: translate(-50%, -50%);
  101. cursor: pointer;
  102. display: flex;
  103. `,[n("slider-handle",`
  104. height: var(--n-handle-size);
  105. width: var(--n-handle-size);
  106. border-radius: 50%;
  107. overflow: hidden;
  108. transition: box-shadow .2s var(--n-bezier), background-color .3s var(--n-bezier);
  109. background-color: var(--n-handle-color);
  110. box-shadow: var(--n-handle-box-shadow);
  111. `,[M("&:hover",`
  112. box-shadow: var(--n-handle-box-shadow-hover);
  113. `)]),M("&:focus",[n("slider-handle",`
  114. box-shadow: var(--n-handle-box-shadow-focus);
  115. `,[M("&:hover",`
  116. box-shadow: var(--n-handle-box-shadow-active);
  117. `)])])])]),n("slider-dots",`
  118. position: absolute;
  119. top: 50%;
  120. left: calc(var(--n-handle-size) / 2);
  121. right: calc(var(--n-handle-size) / 2);
  122. `,[m("transition-disabled",[n("slider-dot","transition: none;")]),n("slider-dot",`
  123. transition:
  124. border-color .3s var(--n-bezier),
  125. box-shadow .3s var(--n-bezier),
  126. background-color .3s var(--n-bezier);
  127. position: absolute;
  128. transform: translate(-50%, -50%);
  129. height: var(--n-dot-height);
  130. width: var(--n-dot-width);
  131. border-radius: var(--n-dot-border-radius);
  132. overflow: hidden;
  133. box-sizing: border-box;
  134. border: var(--n-dot-border);
  135. background-color: var(--n-dot-color);
  136. `,[m("active","border: var(--n-dot-border-active);")])])]),n("slider-handle-indicator",`
  137. font-size: var(--n-font-size);
  138. padding: 6px 10px;
  139. border-radius: var(--n-indicator-border-radius);
  140. color: var(--n-indicator-text-color);
  141. background-color: var(--n-indicator-color);
  142. box-shadow: var(--n-indicator-box-shadow);
  143. `,[ue()]),n("slider-handle-indicator",`
  144. font-size: var(--n-font-size);
  145. padding: 6px 10px;
  146. border-radius: var(--n-indicator-border-radius);
  147. color: var(--n-indicator-text-color);
  148. background-color: var(--n-indicator-color);
  149. box-shadow: var(--n-indicator-box-shadow);
  150. `,[m("top",`
  151. margin-bottom: 12px;
  152. `),m("right",`
  153. margin-left: 12px;
  154. `),m("bottom",`
  155. margin-top: 12px;
  156. `),m("left",`
  157. margin-right: 12px;
  158. `),ue()]),Ge(n("slider",[n("slider-dot","background-color: var(--n-dot-color-modal);")])),Qe(n("slider",[n("slider-dot","background-color: var(--n-dot-color-popover);")]))]),bo=0,go=Object.assign(Object.assign({},ge.props),{to:J.propTo,defaultValue:{type:[Number,Array],default:0},marks:Object,disabled:{type:Boolean,default:void 0},formatTooltip:Function,keyboard:{type:Boolean,default:!0},min:{type:Number,default:0},max:{type:Number,default:100},step:{type:[Number,String],default:1},range:Boolean,value:[Number,Array],placement:String,showTooltip:{type:Boolean,default:void 0},tooltip:{type:Boolean,default:!0},vertical:Boolean,reverse:Boolean,"onUpdate:value":[Function,Array],onUpdateValue:[Function,Array]}),wo=Ze({name:"Slider",props:go,setup(a){const{mergedClsPrefixRef:l,namespaceRef:y,inlineThemeDisabled:f}=Je(a),s=ge("Slider","-slider",mo,fo,a,l),d=x(null),[z,R]=be(),[L,_]=be(),B=x(new Set),$=eo(a),{mergedDisabledRef:D}=$,ee=w(()=>{const{step:e}=a;if(Number(e)<=0||e==="mark")return 0;const o=e.toString();let t=0;return o.includes(".")&&(t=o.length-o.indexOf(".")-1),t}),X=x(a.defaultValue),pe=oo(a,"value"),Y=to(pe,X),b=w(()=>{const{value:e}=Y;return(a.range?e:[e]).map(ie)}),oe=w(()=>b.value.length>2),we=w(()=>a.placement===void 0?a.vertical?"right":"top":a.placement),te=w(()=>{const{marks:e}=a;return e?Object.keys(e).map(parseFloat):null}),g=x(-1),ae=x(-1),C=x(-1),S=x(!1),H=x(!1),K=w(()=>{const{vertical:e,reverse:o}=a;return e?o?"top":"bottom":o?"right":"left"}),xe=w(()=>{if(oe.value)return;const e=b.value,o=F(a.range?Math.min(...e):a.min),t=F(a.range?Math.max(...e):e[0]),{value:r}=K;return a.vertical?{[r]:`${o}%`,height:`${t-o}%`}:{[r]:`${o}%`,width:`${t-o}%`}}),ke=w(()=>{const e=[],{marks:o}=a;if(o){const t=b.value.slice();t.sort((u,h)=>u-h);const{value:r}=K,{value:i}=oe,{range:c}=a,p=i?()=>!1:u=>c?u>=t[0]&&u<=t[t.length-1]:u<=t[0];for(const u of Object.keys(o)){const h=Number(u);e.push({active:p(h),label:o[u],style:{[r]:`${F(h)}%`}})}}return e});function ye(e,o){const t=F(e),{value:r}=K;return{[r]:`${t}%`,zIndex:o===g.value?1:0}}function ne(e){return a.showTooltip||C.value===e||g.value===e&&S.value}function Re(e){return S.value?!(g.value===e&&ae.value===e):!0}function Ce(e){var o;~e&&(g.value=e,(o=z.value.get(e))===null||o===void 0||o.focus())}function Se(){L.value.forEach((e,o)=>{ne(o)&&e.syncPosition()})}function re(e){const{"onUpdate:value":o,onUpdateValue:t}=a,{nTriggerFormInput:r,nTriggerFormChange:i}=$;t&&fe(t,e),o&&fe(o,e),X.value=e,r(),i()}function le(e){const{range:o}=a;if(o){if(Array.isArray(e)){const{value:t}=b;e.join()!==t.join()&&re(e)}}else Array.isArray(e)||b.value[0]!==e&&re(e)}function W(e,o){if(a.range){const t=b.value.slice();t.splice(o,1,e),le(t)}else le(e)}function q(e,o,t){const r=t!==void 0;t||(t=e-o>0?1:-1);const i=te.value||[],{step:c}=a;if(c==="mark"){const h=I(e,i.concat(o),r?t:void 0);return h?h.value:o}if(c<=0)return o;const{value:p}=ee;let u;if(r){const h=Number((o/c).toFixed(p)),k=Math.floor(h),G=h>k?k:k-1,Q=h<k?k:k+1;u=I(o,[Number((G*c).toFixed(p)),Number((Q*c).toFixed(p)),...i],t)}else{const h=Te(e);u=I(e,[...i,h])}return u?ie(u.value):o}function ie(e){return Math.min(a.max,Math.max(a.min,e))}function F(e){const{max:o,min:t}=a;return(e-t)/(o-t)*100}function ze(e){const{max:o,min:t}=a;return t+(o-t)*e}function Te(e){const{step:o,min:t}=a;if(Number(o)<=0||o==="mark")return e;const r=Math.round((e-t)/o)*o+t;return Number(r.toFixed(ee.value))}function I(e,o=te.value,t){if(!(o!=null&&o.length))return null;let r=null,i=-1;for(;++i<o.length;){const c=o[i]-e,p=Math.abs(c);(t===void 0||c*t>0)&&(r===null||p<r.distance)&&(r={index:i,distance:p,value:o[i]})}return r}function se(e){const o=d.value;if(!o)return;const t=me(e)?e.touches[0]:e,r=o.getBoundingClientRect();let i;return a.vertical?i=(r.bottom-t.clientY)/r.height:i=(t.clientX-r.left)/r.width,a.reverse&&(i=1-i),ze(i)}function Ve(e){if(D.value||!a.keyboard)return;const{vertical:o,reverse:t}=a;switch(e.key){case"ArrowUp":e.preventDefault(),A(o&&t?-1:1);break;case"ArrowRight":e.preventDefault(),A(!o&&t?-1:1);break;case"ArrowDown":e.preventDefault(),A(o&&t?1:-1);break;case"ArrowLeft":e.preventDefault(),A(!o&&t?1:-1);break}}function A(e){const o=g.value;if(o===-1)return;const{step:t}=a,r=b.value[o],i=Number(t)<=0||t==="mark"?r:r+t*e;W(q(i,r,e>0?1:-1),o)}function Me(e){var o,t;if(D.value||!me(e)&&e.button!==bo)return;const r=se(e);if(r===void 0)return;const i=b.value.slice(),c=a.range?(t=(o=I(r,i))===null||o===void 0?void 0:o.index)!==null&&t!==void 0?t:-1:0;c!==-1&&(e.preventDefault(),Ce(c),Be(),W(q(r,b.value[c]),c))}function Be(){S.value||(S.value=!0,U("touchend",document,N),U("mouseup",document,N),U("touchmove",document,P),U("mousemove",document,P))}function E(){S.value&&(S.value=!1,O("touchend",document,N),O("mouseup",document,N),O("touchmove",document,P),O("mousemove",document,P))}function P(e){const{value:o}=g;if(!S.value||o===-1){E();return}const t=se(e);W(q(t,b.value[o]),o)}function N(){E()}function $e(e){g.value=e,D.value||(C.value=e)}function De(e){g.value===e&&(g.value=-1,E()),C.value===e&&(C.value=-1)}function He(e){C.value=e}function Fe(e){C.value===e&&(C.value=-1)}he(g,(e,o)=>void Z(()=>ae.value=o)),he(Y,()=>{if(a.marks){if(H.value)return;H.value=!0,Z(()=>{H.value=!1})}Z(Se)}),ao(()=>{E()});const de=w(()=>{const{self:{markFontSize:e,railColor:o,railColorHover:t,fillColor:r,fillColorHover:i,handleColor:c,opacityDisabled:p,dotColor:u,dotColorModal:h,handleBoxShadow:k,handleBoxShadowHover:G,handleBoxShadowActive:Q,handleBoxShadowFocus:Ie,dotBorder:Ae,dotBoxShadow:Ee,railHeight:Pe,railWidthVertical:Ne,handleSize:je,dotHeight:Ue,dotWidth:Oe,dotBorderRadius:Le,fontSize:_e,dotBorderActive:Xe,dotColorPopover:Ye},common:{cubicBezierEaseInOut:Ke}}=s.value;return{"--n-bezier":Ke,"--n-dot-border":Ae,"--n-dot-border-active":Xe,"--n-dot-border-radius":Le,"--n-dot-box-shadow":Ee,"--n-dot-color":u,"--n-dot-color-modal":h,"--n-dot-color-popover":Ye,"--n-dot-height":Ue,"--n-dot-width":Oe,"--n-fill-color":r,"--n-fill-color-hover":i,"--n-font-size":_e,"--n-handle-box-shadow":k,"--n-handle-box-shadow-active":Q,"--n-handle-box-shadow-focus":Ie,"--n-handle-box-shadow-hover":G,"--n-handle-color":c,"--n-handle-size":je,"--n-opacity-disabled":p,"--n-rail-color":o,"--n-rail-color-hover":t,"--n-rail-height":Pe,"--n-rail-width-vertical":Ne,"--n-mark-font-size":e}}),T=f?ve("slider",void 0,de,a):void 0,ce=w(()=>{const{self:{fontSize:e,indicatorColor:o,indicatorBoxShadow:t,indicatorTextColor:r,indicatorBorderRadius:i}}=s.value;return{"--n-font-size":e,"--n-indicator-border-radius":i,"--n-indicator-box-shadow":t,"--n-indicator-color":o,"--n-indicator-text-color":r}}),V=f?ve("slider-indicator",void 0,ce,a):void 0;return{mergedClsPrefix:l,namespace:y,uncontrolledValue:X,mergedValue:Y,mergedDisabled:D,mergedPlacement:we,isMounted:no(),adjustedTo:J(a),dotTransitionDisabled:H,markInfos:ke,isShowTooltip:ne,shouldKeepTooltipTransition:Re,handleRailRef:d,setHandleRefs:R,setFollowerRefs:_,fillStyle:xe,getHandleStyle:ye,activeIndex:g,arrifiedValues:b,followerEnabledIndexSet:B,handleRailMouseDown:Me,handleHandleFocus:$e,handleHandleBlur:De,handleHandleMouseEnter:He,handleHandleMouseLeave:Fe,handleRailKeyDown:Ve,indicatorCssVars:f?void 0:ce,indicatorThemeClass:V==null?void 0:V.themeClass,indicatorOnRender:V==null?void 0:V.onRender,cssVars:f?void 0:de,themeClass:T==null?void 0:T.themeClass,onRender:T==null?void 0:T.onRender}},render(){var a;const{mergedClsPrefix:l,themeClass:y,formatTooltip:f}=this;return(a=this.onRender)===null||a===void 0||a.call(this),v("div",{class:[`${l}-slider`,y,{[`${l}-slider--disabled`]:this.mergedDisabled,[`${l}-slider--active`]:this.activeIndex!==-1,[`${l}-slider--with-mark`]:this.marks,[`${l}-slider--vertical`]:this.vertical,[`${l}-slider--reverse`]:this.reverse}],style:this.cssVars,onKeydown:this.handleRailKeyDown,onMousedown:this.handleRailMouseDown,onTouchstart:this.handleRailMouseDown},v("div",{class:`${l}-slider-rail`},v("div",{class:`${l}-slider-rail__fill`,style:this.fillStyle}),this.marks?v("div",{class:[`${l}-slider-dots`,this.dotTransitionDisabled&&`${l}-slider-dots--transition-disabled`]},this.markInfos.map(s=>v("div",{key:s.label,class:[`${l}-slider-dot`,{[`${l}-slider-dot--active`]:s.active}],style:s.style}))):null,v("div",{ref:"handleRailRef",class:`${l}-slider-handles`},this.arrifiedValues.map((s,d)=>{const z=this.isShowTooltip(d);return v(ro,null,{default:()=>[v(lo,null,{default:()=>v("div",{ref:this.setHandleRefs(d),class:`${l}-slider-handle-wrapper`,tabindex:this.mergedDisabled?-1:0,style:this.getHandleStyle(s,d),onFocus:()=>{this.handleHandleFocus(d)},onBlur:()=>{this.handleHandleBlur(d)},onMouseenter:()=>{this.handleHandleMouseEnter(d)},onMouseleave:()=>{this.handleHandleMouseLeave(d)}},io(this.$slots.thumb,()=>[v("div",{class:`${l}-slider-handle`})]))}),this.tooltip&&v(so,{ref:this.setFollowerRefs(d),show:z,to:this.adjustedTo,enabled:this.showTooltip&&!this.range||this.followerEnabledIndexSet.has(d),teleportDisabled:this.adjustedTo===J.tdkey,placement:this.mergedPlacement,containerClass:this.namespace},{default:()=>v(co,{name:"fade-in-scale-up-transition",appear:this.isMounted,css:this.shouldKeepTooltipTransition(d),onEnter:()=>{this.followerEnabledIndexSet.add(d)},onAfterLeave:()=>{this.followerEnabledIndexSet.delete(d)}},{default:()=>{var R;return z?((R=this.indicatorOnRender)===null||R===void 0||R.call(this),v("div",{class:[`${l}-slider-handle-indicator`,this.indicatorThemeClass,`${l}-slider-handle-indicator--${this.mergedPlacement}`],style:this.indicatorCssVars},typeof f=="function"?f(s):s)):null}})})]})})),this.marks?v("div",{class:`${l}-slider-marks`},this.markInfos.map(s=>v("div",{key:s.label,class:`${l}-slider-mark`,style:s.style},s.label))):null))}});export{wo as N};