index.0874dacb.js 2.2 KB

1
  1. import{E as A,G as N,a0 as T,ab as D,H as G,a_ as O,d as U,ai as W,W as Y,a$ as $,j as u,aq as J,a2 as K,N as B,Y as L,O as Q}from"./ResizeObserver.es.f28023e0.js";import{u as Z}from"./use-refs.b4f9d723.js";const[x,d]=A("rate");function p(a,l,o,i){return a>=l?{status:"full",value:1}:a+.5>=l&&o&&!i?{status:"half",value:.5}:a+1>=l&&o&&i?{status:"half",value:Math.round((a-l+1)*1e10)/1e10}:{status:"void",value:0}}const aa={size:N,icon:T("star"),color:String,count:D(5),gutter:N,readonly:Boolean,disabled:Boolean,voidIcon:T("star-o"),allowHalf:Boolean,voidColor:String,touchable:G,iconPrefix:String,modelValue:O(0),disabledColor:String};var ea=U({name:x,props:aa,emits:["change","update:modelValue"],setup(a,{emit:l}){const o=W(),[i,h]=Z(),v=()=>a.readonly||a.disabled||!a.touchable,_=Y(()=>Array(+a.count).fill("").map((e,t)=>p(a.modelValue,t+1,a.allowHalf,a.readonly)));let s;const b=()=>{const e=i.value.map(L);s=[],e.forEach((t,n)=>{a.allowHalf?s.push({score:n+.5,left:t.left},{score:n+1,left:t.left+t.width/2}):s.push({score:n+1,left:t.left})})},g=e=>{for(let t=s.length-1;t>0;t--)if(e>s[t].left)return s[t].score;return a.allowHalf?.5:1},y=e=>{!a.disabled&&!a.readonly&&e!==a.modelValue&&(l("update:modelValue",e),l("change",e))},E=e=>{v()||(o.start(e),b())},F=e=>{if(!v()&&(o.move(e),o.isHorizontal())){const{clientX:t}=e.touches[0];J(e),y(g(t))}},M=(e,t)=>{const{icon:n,size:P,color:R,count:S,gutter:V,voidIcon:C,disabled:r,voidColor:k,allowHalf:w,iconPrefix:H,disabledColor:z}=a,f=t+1,m=e.status==="full",c=e.status==="void",X=w&&e.value>0&&e.value<1;let I;V&&f!==+S&&(I={paddingRight:K(V)});const j=q=>{b(),y(w?g(q.clientX):f)};return u("div",{key:t,ref:h(t),role:"radio",style:I,class:d("item"),tabindex:r?void 0:0,"aria-setsize":S,"aria-posinset":f,"aria-checked":!c,onClick:j},[u(B,{size:P,name:m?n:C,class:d("icon",{disabled:r,full:m}),color:r?z:m?R:k,classPrefix:H},null),X&&u(B,{size:P,style:{width:e.value+"em"},name:c?C:n,class:d("icon",["half",{disabled:r,full:!c}]),color:r?z:c?k:R,classPrefix:H},null)])};return $(()=>a.modelValue),()=>u("div",{role:"radiogroup",class:d({readonly:a.readonly,disabled:a.disabled}),tabindex:a.disabled?void 0:0,"aria-disabled":a.disabled,"aria-readonly":a.readonly,onTouchstart:E,onTouchmove:F},[_.value.map(M)])}});const oa=Q(ea);export{oa as R};