1 |
- import{E as D,G as N,a0 as T,ab as G,H as O,a_ as U,d as W,ai as Y,W as $,a$ as j,i as u,aq as J,a2 as K,N as B,Y as L,O as Q}from"./index.7994470a.js";import{u as Z}from"./use-refs.ad5f4144.js";const[x,d]=D("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:G(5),gutter:N,readonly:Boolean,disabled:Boolean,voidIcon:T("star-o"),allowHalf:Boolean,voidColor:String,touchable:O,iconPrefix:String,modelValue:U(0),disabledColor:String};var ea=W({name:x,props:aa,emits:["change","update:modelValue"],setup(a,{emit:l}){const o=Y(),[i,h]=Z(),v=()=>a.readonly||a.disabled||!a.touchable,_=$(()=>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 q=A=>{b(),y(w?g(A.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:q},[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 j(()=>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};
|