index-fWeoxGxY.js 7.3 KB

1
  1. import{I as W,P as F,k as J,m as U,_ as $,r as Y,l as q,z as Q,a as Z,j as k,b as P,K as D,G as ee}from"./bootstrap-BcAf5ut0.js";import{x as y,a4 as L,J as te,P as ne,T as le,Y as ae,a9 as oe}from"../jse/index-index-CTvWBEcQ.js";import{T as re}from"./index-DxUmZom-.js";import{u as se}from"./useRefs-CONmYVWe.js";import{u as ie}from"./FormItemContext-fvdlX2Jo.js";import"./Trigger-BMBnz4_5.js";import"./vnode-9TBgietd.js";import"./ResizeObserver.es-CDE7jhPe.js";import"./colors-CKalYN3D.js";function ce(e){let t=e.scrollX;const a="scrollLeft";if(typeof t!="number"){const s=e.document;t=s.documentElement[a],typeof t!="number"&&(t=s.body[a])}return t}function ue(e){let t,a;const s=e.ownerDocument,{body:i}=s,S=s&&s.documentElement,h=e.getBoundingClientRect();return t=h.left,a=h.top,t-=S.clientLeft||i.clientLeft||0,a-=S.clientTop||i.clientTop||0,{left:t,top:a}}function de(e){const t=ue(e),a=e.ownerDocument,s=a.defaultView||a.parentWindow;return t.left+=ce(s),t.left}var fe={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3a32.05 32.05 0 00.6 45.3l183.7 179.1-43.4 252.9a31.95 31.95 0 0046.4 33.7L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3z"}}]},name:"star",theme:"filled"};function T(e){for(var t=1;t<arguments.length;t++){var a=arguments[t]!=null?Object(arguments[t]):{},s=Object.keys(a);typeof Object.getOwnPropertySymbols=="function"&&(s=s.concat(Object.getOwnPropertySymbols(a).filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable}))),s.forEach(function(i){ve(e,i,a[i])})}return e}function ve(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}var V=function(t,a){var s=T({},t,a.attrs);return y(W,T({},s,{icon:fe}),null)};V.displayName="StarFilled";V.inheritAttrs=!1;const me={value:Number,index:Number,prefixCls:String,allowHalf:{type:Boolean,default:void 0},disabled:{type:Boolean,default:void 0},character:F.any,characterRender:Function,focused:{type:Boolean,default:void 0},count:Number,onClick:Function,onHover:Function},he=L({compatConfig:{MODE:3},name:"Star",inheritAttrs:!1,props:me,emits:["hover","click"],setup(e,t){let{emit:a}=t;const s=o=>{const{index:d}=e;a("hover",o,d)},i=o=>{const{index:d}=e;a("click",o,d)},S=o=>{const{index:d}=e;o.keyCode===13&&a("click",o,d)},h=te(()=>{const{prefixCls:o,index:d,value:p,allowHalf:g,focused:v}=e,b=d+1;let m=o;return p===0&&d===0&&v?m+=` ${o}-focused`:g&&p+.5>=b&&p<b?(m+=` ${o}-half ${o}-active`,v&&(m+=` ${o}-focused`)):(m+=b<=p?` ${o}-full`:` ${o}-zero`,b===p&&v&&(m+=` ${o}-focused`)),m});return()=>{const{disabled:o,prefixCls:d,characterRender:p,character:g,index:v,count:b,value:m}=e,n=typeof g=="function"?g({disabled:o,prefixCls:d,index:v,count:b,value:m}):g;let C=y("li",{class:h.value},[y("div",{onClick:o?null:i,onKeydown:o?null:S,onMousemove:o?null:s,role:"radio","aria-checked":m>v?"true":"false","aria-posinset":v+1,"aria-setsize":b,tabindex:o?-1:0},[y("div",{class:`${d}-first`},[n]),y("div",{class:`${d}-second`},[n])])]);return p&&(C=p(C,e)),C}}}),pe=e=>{const{componentCls:t}=e;return{[`${t}-star`]:{position:"relative",display:"inline-block",color:"inherit",cursor:"pointer","&:not(:last-child)":{marginInlineEnd:e.marginXS},"> div":{transition:`all ${e.motionDurationMid}, outline 0s`,"&:hover":{transform:e.rateStarHoverScale},"&:focus":{outline:0},"&:focus-visible":{outline:`${e.lineWidth}px dashed ${e.rateStarColor}`,transform:e.rateStarHoverScale}},"&-first, &-second":{color:e.defaultColor,transition:`all ${e.motionDurationMid}`,userSelect:"none",[e.iconCls]:{verticalAlign:"middle"}},"&-first":{position:"absolute",top:0,insetInlineStart:0,width:"50%",height:"100%",overflow:"hidden",opacity:0},[`&-half ${t}-star-first, &-half ${t}-star-second`]:{opacity:1},[`&-half ${t}-star-first, &-full ${t}-star-second`]:{color:"inherit"}}}},ge=e=>({[`&-rtl${e.componentCls}`]:{direction:"rtl"}}),be=e=>{const{componentCls:t}=e;return{[t]:$($($($($({},Y(e)),{display:"inline-block",margin:0,padding:0,color:e.rateStarColor,fontSize:e.rateStarSize,lineHeight:"unset",listStyle:"none",outline:"none",[`&-disabled${t} ${t}-star`]:{cursor:"default","&:hover":{transform:"scale(1)"}}}),pe(e)),{[`+ ${t}-text`]:{display:"inline-block",marginInlineStart:e.marginXS,fontSize:e.fontSize}}),ge(e))}},ye=J("Rate",e=>{const{colorFillContent:t}=e,a=U(e,{rateStarColor:e["yellow-6"],rateStarSize:e.controlHeightLG*.5,rateStarHoverScale:"scale(1.1)",defaultColor:t});return[be(a)]}),Se=()=>({prefixCls:String,count:Number,value:Number,allowHalf:{type:Boolean,default:void 0},allowClear:{type:Boolean,default:void 0},tooltips:Array,disabled:{type:Boolean,default:void 0},character:F.any,autofocus:{type:Boolean,default:void 0},tabindex:F.oneOfType([F.number,F.string]),direction:String,id:String,onChange:Function,onHoverChange:Function,"onUpdate:value":Function,onFocus:Function,onBlur:Function,onKeydown:Function}),Ce=L({compatConfig:{MODE:3},name:"ARate",inheritAttrs:!1,props:Q(Se(),{value:0,count:5,allowHalf:!1,allowClear:!0,tabindex:0,direction:"ltr"}),setup(e,t){let{slots:a,attrs:s,emit:i,expose:S}=t;const{prefixCls:h,direction:o}=Z("rate",e),[d,p]=ye(h),g=ie(),v=ne(),[b,m]=se(),n=le({value:e.value,focused:!1,cleanedValue:null,hoverValue:void 0});ae(()=>e.value,()=>{n.value=e.value});const C=l=>ee(m.value.get(l)),O=(l,c)=>{const r=o.value==="rtl";let u=l+1;if(e.allowHalf){const f=C(l),H=de(f),R=f.clientWidth;(r&&c-H>R/2||!r&&c-H<R/2)&&(u-=.5)}return u},w=l=>{e.value===void 0&&(n.value=l),i("update:value",l),i("change",l),g.onFieldChange()},M=(l,c)=>{const r=O(c,l.pageX);r!==n.cleanedValue&&(n.hoverValue=r,n.cleanedValue=null),i("hoverChange",r)},B=()=>{n.hoverValue=void 0,n.cleanedValue=null,i("hoverChange",void 0)},E=(l,c)=>{const{allowClear:r}=e,u=O(c,l.pageX);let f=!1;r&&(f=u===n.value),B(),w(f?0:u),n.cleanedValue=f?u:null},z=l=>{n.focused=!0,i("focus",l)},j=l=>{n.focused=!1,i("blur",l),g.onFieldBlur()},A=l=>{const{keyCode:c}=l,{count:r,allowHalf:u}=e,f=o.value==="rtl";c===D.RIGHT&&n.value<r&&!f?(u?n.value+=.5:n.value+=1,w(n.value),l.preventDefault()):c===D.LEFT&&n.value>0&&!f||c===D.RIGHT&&n.value>0&&f?(u?n.value-=.5:n.value-=1,w(n.value),l.preventDefault()):c===D.LEFT&&n.value<r&&f&&(u?n.value+=.5:n.value+=1,w(n.value),l.preventDefault()),i("keydown",l)},I=()=>{e.disabled||v.value.focus()};S({focus:I,blur:()=>{e.disabled||v.value.blur()}}),oe(()=>{const{autofocus:l,disabled:c}=e;l&&!c&&I()});const K=(l,c)=>{let{index:r}=c;const{tooltips:u}=e;return u?y(re,{title:u[r]},{default:()=>[l]}):l};return()=>{const{count:l,allowHalf:c,disabled:r,tabindex:u,id:f=g.id.value}=e,{class:H,style:R}=s,N=[],X=r?`${h.value}-disabled`:"",_=e.character||a.character||(()=>y(V,null,null));for(let x=0;x<l;x++)N.push(y(he,{ref:b(x),key:x,index:x,count:l,disabled:r,prefixCls:`${h.value}-star`,allowHalf:c,value:n.hoverValue===void 0?n.value:n.hoverValue,onClick:E,onHover:M,character:_,characterRender:K,focused:n.focused},null));const G=k(h.value,X,H,{[p.value]:!0,[`${h.value}-rtl`]:o.value==="rtl"});return d(y("ul",P(P({},s),{},{id:f,class:G,style:R,onMouseleave:r?null:B,tabindex:r?-1:u,onFocus:r?null:z,onBlur:r?null:j,onKeydown:r?null:A,ref:v,role:"radiogroup"}),[N]))}}}),Ie=q(Ce);export{Ie as default,Se as rateProps};