1 |
- import{A as D,E as N,$ as T,aa as G,G as U,aZ as Z,d as $,ah as q,V as J,a_ as K,j as u,ap as L,a1 as O,M as B,X as Q,N as W}from"./index.394decd7.js";import{u as Y}from"./use-refs.09b2d19c.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:U,iconPrefix:String,modelValue:Z(0),disabledColor:String};var ea=$({name:x,props:aa,emits:["change","update:modelValue"],setup(a,{emit:l}){const o=q(),[i,h]=Y(),v=()=>a.readonly||a.disabled||!a.touchable,M=J(()=>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(Q);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))},X=e=>{v()||(o.start(e),b())},_=e=>{if(!v()&&(o.move(e),o.isHorizontal())){const{clientX:t}=e.touches[0];L(e),y(g(t))}},A=(e,t)=>{const{icon:n,size:P,color:V,count:R,gutter:S,voidIcon:C,disabled:r,voidColor:k,allowHalf:w,iconPrefix:z,disabledColor:H}=a,f=t+1,m=e.status==="full",c=e.status==="void",E=w&&e.value>0&&e.value<1;let I;S&&f!==+R&&(I={paddingRight:O(S)});const F=j=>{b(),y(w?g(j.clientX):f)};return u("div",{key:t,ref:h(t),role:"radio",style:I,class:d("item"),tabindex:r?void 0:0,"aria-setsize":R,"aria-posinset":f,"aria-checked":!c,onClick:F},[u(B,{size:P,name:m?n:C,class:d("icon",{disabled:r,full:m}),color:r?H:m?V:k,classPrefix:z},null),E&&u(B,{size:P,style:{width:e.value+"em"},name:c?C:n,class:d("icon",["half",{disabled:r,full:!c}]),color:r?H:c?k:V,classPrefix:z},null)])};return K(()=>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:X,onTouchmove:_},[M.value.map(A)])}});const oa=W(ea);export{oa as R};
|