vue-data-ui-hq
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
2 lines (1 loc) • 11.6 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("./index-ZfICPrrM.cjs"),D=require("./useNestedProp-C14rfl0j.cjs"),A=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),R={key:0,class:"vue-ui-rating-title",style:{width:"100%"}},X=["src","height","width"],j=["xmlns","height","width"],F=["id"],I=["stop-color"],O=["stop-color"],Y=["points","fill","stroke","stroke-width"],G=["src","alt","height","width","id"],U=["xmlns","viewBox","height","id"],q=["id"],H=["stop-color"],K=["stop-color"],P=["points","fill","stroke"],T=["xmlns","height"],W=["onClick","onMouseenter","onKeyup"],J=["onMouseenter"],Q={__name:"vue-ui-rating",props:{config:{type:Object,default(){return{}}},dataset:{type:Object,default(){return{}}}},emits:["rate"],setup(k,{expose:S,emit:_}){const{vue_ui_rating:w}=r.useConfig(),i=k,d=e.ref(r.createUid()),g=e.ref(!1),s=e.ref(void 0),y=e.ref([]),z=e.useSlots();e.onMounted(()=>{z["chart-background"]&&console.warn("VueUiRating does not support the #chart-background slot.")});const B=_,t=e.computed({get:()=>m(),set:o=>o});function m(){return D.useNestedProp({userConfig:i.config,defaultConfig:w})}e.watch(()=>i.config,o=>{t.value=m(),h()},{deep:!0});const N=e.computed(()=>typeof i.dataset.rating=="object"&&!Array.isArray(i.dataset.rating)?E(i.dataset.rating):i.dataset.rating),C=e.computed(()=>typeof i.dataset.rating=="object"&&!Array.isArray(i.dataset.rating)),a=e.ref(N.value),v=e.computed(()=>t.value.type==="image"),f=e.computed(()=>t.value.readonly);function E(o){let l=0,n=0;for(const u in o){const M=parseInt(u),$=o[u];l+=M*$,n+=$}if(n===0)return 0;const c=l/n;return Math.min(t.value.to,Math.max(t.value.from,c))}e.onMounted(()=>{h()});function h(){r.objectIsEmpty(i.dataset)&&r.error({componentName:"VueUiRating",type:"dataset"}),y.value=[];for(let o=t.value.from;o<=t.value.to;o+=1)y.value.push(o)}function p(o,l=!1){return o>s.value||f.value?l?t.value.style.image.inactiveOpacity:t.value.style.star.inactiveColor:l?1:t.value.style.star.useGradient?`url(#star_gradient_under_${d.value})`:t.value.style.star.activeColor}function x(o,l=!1){const n=a.value-o,c=l?1:100;switch(!0){case n<=0:return .001;case n>1:return 1*c;default:return n*c}}function b(o){f.value||(a.value=o,B("rate",o))}function V(){return a.value}function L(o=!0){f.value=o}return S({getData:V,toggleReadonly:L}),(o,l)=>(e.openBlock(),e.createElementBlock("div",{style:e.normalizeStyle(`background:${e.unref(t).style.backgroundColor};font-family:${e.unref(t).style.fontFamily};width:100%`),class:"vue-ui-rating",onMouseover:l[2]||(l[2]=n=>g.value=!0),onMouseleave:l[3]||(l[3]=n=>{g.value=!1,s.value=void 0})},[e.unref(t).style.title.text?(e.openBlock(),e.createElementBlock("div",R,[e.createElementVNode("div",{style:e.normalizeStyle(`color:${e.unref(t).style.title.color};font-weight:${e.unref(t).style.title.bold?"bold":"normal"};text-align:${e.unref(t).style.title.textAlign};margin-bottom:${e.unref(t).style.title.offsetY}px;font-size:${e.unref(t).style.title.fontSize}px`)},e.toDisplayString(e.unref(t).style.title.text),5),e.unref(t).style.title.subtitle.text?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(`color:${e.unref(t).style.title.subtitle.color};font-size:${e.unref(t).style.title.subtitle.fontSize}px;text-align:${e.unref(t).style.title.textAlign};margin-bottom:${e.unref(t).style.title.subtitle.offsetY}px;font-weight:${e.unref(t).style.title.subtitle.bold?"bold":"normal"}`)},e.toDisplayString(e.unref(t).style.title.subtitle.text),5)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.unref(t).style.rating.show&&e.unref(t).style.rating.position==="top"?(e.openBlock(),e.createElementBlock("div",{key:1,style:e.normalizeStyle(`width:100%;text-align:center;margin-bottom:${e.unref(t).style.rating.offsetY}px;font-size:${e.unref(t).style.rating.fontSize}px;font-weight:${e.unref(t).style.rating.bold?"bold":"normal"};margin-left:${e.unref(t).style.rating.offsetX}px`)},e.toDisplayString(e.unref(r.applyDataLabel)(e.unref(t).style.rating.formatter,e.unref(a),e.unref(r.dataLabel)({v:e.unref(a),r:e.unref(t).style.rating.roundingValue}),e.unref(t))),5)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"vue-ui-rating-wrapper",style:e.normalizeStyle(`height:${e.unref(t).style.itemSize}px;width:100%;display:flex;align-items:center;justify-content:center`)},[e.unref(t).style.rating.show&&e.unref(t).style.rating.position==="left"?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(`width:fit-content;text-align:center;margin-bottom:${e.unref(t).style.rating.offsetY}px;font-size:${e.unref(t).style.rating.fontSize}px;font-weight:${e.unref(t).style.rating.bold?"bold":"normal"};padding-right:${e.unref(t).style.rating.offsetX}px`)},e.toDisplayString(e.unref(r.applyDataLabel)(e.unref(t).style.rating.formatter,e.unref(a),e.unref(r.dataLabel)({v:e.unref(a),r:e.unref(t).style.rating.roundingValue}),e.unref(t))),5)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(y),(n,c)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-ui-rating-unit-container",style:e.normalizeStyle(`position:relative;height:${e.unref(t).style.itemSize}px;width:${e.unref(t).style.itemSize}px`)},[e.unref(v)?(e.openBlock(),e.createElementBlock("img",{key:0,src:e.unref(t).style.image.src,height:e.unref(t).style.itemSize,width:e.unref(t).style.itemSize,class:"vue-ui-rating-unit",style:e.normalizeStyle(`position:absolute;top:0;left:0;opacity:${isNaN(e.unref(s))?e.unref(t).style.image.inactiveOpacity:p(n,!0)}`)},null,12,X)):(e.openBlock(),e.createElementBlock("svg",{key:1,xmlns:e.unref(r.XMLNS),viewBox:"0 0 100 100",height:e.unref(t).style.itemSize,width:e.unref(t).style.itemSize,class:"vue-ui-rating-unit"},[e.createElementVNode("defs",null,[e.createElementVNode("radialGradient",{cx:"50%",cy:"50%",r:"50%",fx:"50%",fy:"50%",id:`star_gradient_under_${e.unref(d)}`},[e.createElementVNode("stop",{offset:"0%","stop-color":`${e.unref(r.shiftHue)(e.unref(t).style.star.activeColor,.05)}`},null,8,I),e.createElementVNode("stop",{offset:"100%","stop-color":e.unref(t).style.star.activeColor},null,8,O)],8,F)]),e.createElementVNode("polygon",{points:e.unref(r.createStar)({plot:{x:50,y:50},radius:30,apexes:e.unref(t).style.star.apexes}),fill:isNaN(e.unref(s))?e.unref(t).style.star.inactiveColor:p(n),stroke:e.unref(t).style.star.borderColor?e.unref(t).style.star.borderColor:e.unref(s)?p(n):e.unref(t).style.star.inactiveColor,"stroke-width":e.unref(t).style.star.borderWidth,"stroke-linecap":"round","stroke-linejoin":"round"},null,8,Y)],8,j)),e.unref(v)?(e.openBlock(),e.createElementBlock("img",{key:2,src:e.unref(t).style.image.src,alt:`${e.unref(t).style.image.alt} ${n}`,height:e.unref(t).style.itemSize,width:e.unref(t).style.itemSize,id:`active_${e.unref(d)}_${n}`,class:"vue-ui-rating-unit",style:e.normalizeStyle(`position:absolute;top:0;left:0;clip:rect(0px,${x(c,!0)*e.unref(t).style.itemSize}px,${e.unref(t).style.itemSize}px,0px`)},null,12,G)):(e.openBlock(),e.createElementBlock("svg",{key:3,xmlns:e.unref(r.XMLNS),viewBox:`0 0 ${x(c)} 100`,height:e.unref(t).style.itemSize,class:"vue-ui-rating-unit",id:`active_${e.unref(d)}_${n}`,style:{position:"absolute",top:"0",left:"0"}},[e.createElementVNode("defs",null,[e.createElementVNode("radialGradient",{cx:"50%",cy:"50%",r:"50%",fx:"50%",fy:"50%",id:`star_gradient_over_${e.unref(d)}`},[e.createElementVNode("stop",{offset:"0%","stop-color":`${e.unref(r.shiftHue)(e.unref(t).style.star.activeColor,.05)}`},null,8,H),e.createElementVNode("stop",{offset:"100%","stop-color":e.unref(t).style.star.activeColor},null,8,K)],8,q)]),e.createElementVNode("polygon",{points:e.unref(r.createStar)({plot:{x:50,y:50},radius:30,apexes:e.unref(t).style.star.apexes}),fill:e.unref(t).style.star.useGradient?`url(#star_gradient_over_${e.unref(d)})`:e.unref(t).style.star.activeColor,stroke:e.unref(t).style.star.activeColor},null,8,P)],8,U)),(e.openBlock(),e.createElementBlock("svg",{xmlns:e.unref(r.XMLNS),viewBox:"0 0 100 100",height:e.unref(t).style.itemSize,class:"vue-ui-rating-unit",style:e.normalizeStyle(`position:absolute;top:0;left:0;${e.unref(f)?"":"cursor:pointer"}`)},[e.unref(f)?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("rect",{key:0,class:"vue-ui-rating-mouse-trap",x:0,y:0,width:100,height:100,fill:"transparent",onClick:u=>b(n),onMouseenter:u=>s.value=n,onMouseleave:l[0]||(l[0]=u=>s.value=void 0),tabindex:"0",onKeyup:e.withKeys(u=>b(n),["enter"])},null,40,W)),e.unref(f)?(e.openBlock(),e.createElementBlock("rect",{key:1,class:"vue-ui-rating-mouse-trap",x:0,y:0,width:100,height:100,fill:"transparent",onMouseenter:u=>s.value=n,onMouseleave:l[1]||(l[1]=u=>s.value=void 0)},null,40,J)):e.createCommentVNode("",!0)],12,T)),e.unref(t).style.tooltip.show&&e.unref(C)&&e.unref(f)?(e.openBlock(),e.createElementBlock("div",{key:4,class:"vue-ui-rating-tooltip",style:e.normalizeStyle(`border:1px solid ${e.unref(t).style.tooltip.borderColor};position:absolute;top:${-48+e.unref(t).style.tooltip.offsetY}px;left:50%;transform:translateX(-50%);width:fit-content;text-align:center;background:${e.unref(t).style.tooltip.backgroundColor};display:${e.unref(s)===n?"block":"none"};padding:2px 12px;border-radius:${e.unref(t).style.tooltip.borderRadius}px;box-shadow:${e.unref(t).style.tooltip.boxShadow}`)},[e.createElementVNode("div",{style:e.normalizeStyle(`width:100%;display:flex;flex-direction:row;gap:6px;position:relative;text-align:center;color:${e.unref(t).style.tooltip.color}`)},[e.createElementVNode("span",{style:e.normalizeStyle(`font-size:${e.unref(t).style.tooltip.fontSize}px`)},e.toDisplayString(n)+":",5),e.createElementVNode("span",{style:e.normalizeStyle(`font-weight:${e.unref(t).style.tooltip.bold?"bold":"normal"};font-size:${e.unref(t).style.tooltip.fontSize}px`)},e.toDisplayString(e.unref(r.applyDataLabel)(e.unref(t).style.tooltip.formatter,i.dataset.rating[n],e.unref(r.dataLabel)({v:i.dataset.rating[n],r:e.unref(t).style.tooltip.roundingValue}),e.unref(t))),5),e.createElementVNode("div",{style:e.normalizeStyle(`font-family:Arial !important;position:absolute;top:calc(100% - 4px);left:50%;transform:translateX(-50%);color:${e.unref(t).style.tooltip.borderColor}`)}," ▼ ",4)],4)],4)):e.createCommentVNode("",!0)],4))),256)),e.unref(t).style.rating.show&&e.unref(t).style.rating.position==="right"?(e.openBlock(),e.createElementBlock("div",{key:1,style:e.normalizeStyle(`width:fit-content;text-align:center;margin-bottom:${e.unref(t).style.rating.offsetY}px;font-size:${e.unref(t).style.rating.fontSize}px;font-weight:${e.unref(t).style.rating.bold?"bold":"normal"};padding-left:${e.unref(t).style.rating.offsetX}px`)},e.toDisplayString(e.unref(r.applyDataLabel)(e.unref(t).style.rating.formatter,e.unref(a),e.unref(r.dataLabel)({v:e.unref(a),r:e.unref(t).style.rating.roundingValue}),e.unref(t))),5)):e.createCommentVNode("",!0)],4),e.unref(t).style.rating.show&&e.unref(t).style.rating.position==="bottom"?(e.openBlock(),e.createElementBlock("div",{key:2,style:e.normalizeStyle(`width:100%;text-align:center;margin-top:${e.unref(t).style.rating.offsetY}px;font-size:${e.unref(t).style.rating.fontSize}px;font-weight:${e.unref(t).style.rating.bold?"bold":"normal"};margin-left:${e.unref(t).style.rating.offsetX}px`)},e.toDisplayString(e.unref(r.applyDataLabel)(e.unref(t).style.rating.formatter,e.unref(a),e.unref(r.dataLabel)({v:e.unref(a),r:e.unref(t).style.rating.roundingValue}),e.unref(t))),5)):e.createCommentVNode("",!0)],36))}},Z=A._export_sfc(Q,[["__scopeId","data-v-3c80f07b"]]);exports.default=Z;
;