import{_ as t}from"./uni-icons.BmNngUg_.js";import{aq as s,y as o,z as r,o as e,c as a,w as h,t as i,G as l,a0 as c,v as n,R as b,A as g,x as u,C as d,F as m,D as f,i as p,q as v,Q as _}from"./index-DL8B2Mxu.js";import{r as x}from"./uni-app.es.BSVEa1f2.js";import{_ as C}from"./_plugin-vue_export-helper.BCo6x5W8.js";const F={colorList:[{r:244,g:67,b:54,a:1},{r:233,g:30,b:99,a:1},{r:156,g:39,b:176,a:1},{r:103,g:58,b:183,a:1},{r:63,g:81,b:181,a:1},{r:33,g:150,b:243,a:1},{r:3,g:169,b:244,a:1},{r:0,g:188,b:212,a:1},{r:0,g:150,b:136,a:1},{r:76,g:175,b:80,a:1},{r:139,g:195,b:74,a:1},{r:205,g:220,b:57,a:1},{r:255,g:235,b:59,a:1},{r:255,g:193,b:7,a:1},{r:255,g:152,b:0,a:1},{r:255,g:87,b:34,a:1},{r:121,g:85,b:72,a:1},{r:158,g:158,b:158,a:1},{r:0,g:0,b:0,a:.5},{r:0,g:0,b:0,a:0}],hsv2rgb(t,s,o){t=6*this.bound01(t,360),s=this.bound01(s,100),o=this.bound01(o,100);const r=Math.floor(t),e=t-r,a=o*(1-s),h=o*(1-e*s),i=o*(1-(1-e)*s),l=r%6,c=[o,h,a,a,i,o][l],n=[i,o,o,h,a,a][l],b=[a,a,i,o,o,h][l];return{r:Math.round(255*c),g:Math.round(255*n),b:Math.round(255*b),a:1}},bound01(t,s){this.isOnePointZero(t)&&(t="100%");const o=this.isPercentage(t);return t=Math.min(s,Math.max(0,parseFloat(t))),o&&(t=parseInt(t*s,10)/100),Math.abs(t-s)<1e-6?1:t%s/parseFloat(s)},isPercentage:t=>"string"==typeof t&&-1!==t.indexOf("%"),isOnePointZero:t=>"string"==typeof t&&-1!==t.indexOf(".")&&1===parseFloat(t),rgb2hsl(t,s,o){t/=255,s/=255,o/=255;var r,e,a=Math.min(t,s,o),h=Math.max(t,s,o),i=(a+h)/2,l=h-a;if(h==a)r=0,e=0;else{switch(e=i>.5?l/(2-h-a):l/(h+a),h){case t:r=(s-o)/l+(s{r[s]&&(o[r[s]]=t)})),o}return s},hsv2rgb(t,s,o){t=6*this.bound01(t,360),s=this.bound01(s,100),o=this.bound01(o,100);const r=Math.floor(t),e=t-r,a=o*(1-s),h=o*(1-e*s),i=o*(1-(1-e)*s),l=r%6,c=[o,h,a,a,i,o][l],n=[i,o,o,h,a,a][l],b=[a,a,i,o,o,h][l];return{r:Math.round(255*c),g:Math.round(255*n),b:Math.round(255*b),a:1}},hsl2rgb(t,s,o){t/=360,o/=100;let r=[],e=["r","g","b"],a={r:0,g:0,b:0,a:1};if(0==(s/=100))r=[Math.round(255*o),Math.round(255*o),Math.round(255*o)];else{var h=o>=.5?o+s-o*s:o*(1+s),i=2*o-h;r[0]=t+1/3,r[1]=t,r[2]=t-1/3;for(var l=0;l1&&(c-=1),!0){case c<1/6:c=i+6*(h-i)*c;break;case 1/6<=c&&c<.5:c=h;break;case.5<=c&&c<2/3:c=i+(h-i)*(4-6*c);break;default:c=i}r[l]=Math.round(255*c),a[e[l]]=r[l]}}return a},rgbToHsb(t){let s={h:0,s:0,b:0},o=Math.min(t.r,t.g,t.b),r=Math.max(t.r,t.g,t.b),e=r-o;return s.b=r,s.s=0!=r?255*e/r:0,0!=s.s?t.r==r?s.h=(t.g-t.b)/e:t.g==r?s.h=2+(t.b-t.r)/e:s.h=4+(t.r-t.g)/e:s.h=-1,s.h*=60,s.h<0&&(s.h=0),s.s*=100/255,s.b*=100/255,s},HSBToRGB(t){let s={},o=Math.round(t.h),r=Math.round(255*t.s/100),e=Math.round(255*t.b/100);if(0==r)s.r=s.g=s.b=e;else{let t=e,a=(255-r)*e/255,h=o%60*(t-a)/60;360==o&&(o=0),o<60?(s.r=t,s.b=a,s.g=a+h):o<120?(s.g=t,s.b=a,s.r=t-h):o<180?(s.g=t,s.r=a,s.b=a+h):o<240?(s.b=t,s.r=a,s.g=t-h):o<300?(s.b=t,s.g=a,s.r=a+h):o<360?(s.r=t,s.g=a,s.b=t-h):(s.r=0,s.g=0,s.b=0)}return{r:Math.round(s.r),g:Math.round(s.g),b:Math.round(s.b)}}};const k=C({name:"jnpf-color-picker",components:{tColorPicker:C({props:{color:{default:""},colorFormat:{default:"hex"},isCommonColor:{type:Boolean,default:!1}},data:()=>({show:!1,active:!1,rgba:{r:0,g:0,b:0,a:1},hsb:{h:0,s:0,b:0},site:[{top:0,left:0},{left:0},{left:0}],index:0,bgcolor:{r:255,g:0,b:0,a:1},hex:"#000000",hsvList:["h","s","v"],hsvObj:{},hslList:["h","s","l"],hslObj:{},colorVal:"#000000",hsv:"",rgbObj:{},rgbList:["r","g","b"],rgbaList:["r","g","b","a"],rgbaObj:{},hsl:"",conversion:F}),created(){},methods:{open(){this.show=!0,this.$nextTick((()=>{this.init(),setTimeout((()=>{this.active=!0,setTimeout((()=>{this.getSelectorQuery()}),350)}),50)}))},init(){this.color&&("rgb"==this.colorFormat||"rgba"==this.colorFormat||"hsv"==this.colorFormat||"hsl"==this.colorFormat?(this.color.match(/\(([^)]*)\)/)[1].split(",").forEach(((t,s)=>{this.$set(this[this.colorFormat+"Obj"],this[this.colorFormat+"List"][s],t)})),"rgb"!=this.colorFormat&&"rgba"!=this.colorFormat||(this.rgba=this[this.colorFormat+"Obj"],this.hsb=F.rgbToHex(this.rgba),this.setValue(this.rgba)),"hsv"==this.colorFormat&&(this.rgba=F.hsv2rgb(this[this.colorFormat+"Obj"].h,this[this.colorFormat+"Obj"].s,this[this.colorFormat+"Obj"].v),this.hsb=F.rgbToHex(this.rgba),this.setValue(this.rgba)),"hsl"==this.colorFormat&&(this.rgba=F.hsl2rgb(parseInt(this.hslObj.h),parseInt(this.hslObj.s),parseInt(this.hslObj.l)),this.hsb=F.rgbToHex(this.rgba),this.setValue(this.rgba))):(this.rgba=F.hex2rgba(this.color),this.hsb=F.rgbToHex(this.rgba),this.setValue(this.rgba)))},moveHandle(){},close(){this.active=!1,this.$nextTick((()=>{setTimeout((()=>{this.show=!1}),500)}))},confirm(){this.$emit("confirm",{rgba:this.rgba,hex:this.hex,colorVal:this.colorVal,hsv:this.hsv,hsl:this.hsl}),this.close()},selectColor(t){this.setColorBySelect(t)},touchstart(t,s){const{clientX:o,clientY:r}=t.touches[0];this.pageX=o,this.pageY=r,this.setPosition(o,r,s)},touchmove(t,s){const{clientX:o,clientY:r}=t.touches[0];this.moveX=o,this.moveY=r,this.setPosition(o,r,s)},touchend(t,s){},setPosition(t,s,o){this.index=o;const{top:r,left:e,width:a,height:h}=this.position[o];this.site[o].left=Math.max(0,Math.min(parseInt(t-e),a)),0===o?(this.site[o].top=Math.max(0,Math.min(parseInt(s-r),h)),this.hsb.s=parseInt(100*this.site[o].left/a),this.hsb.b=parseInt(100-100*this.site[o].top/h),this.setColor(),this.setValue(this.rgba)):this.setControl(o,this.site[o].left)},setColor(){const t=F.HSBToRGB(this.hsb);this.rgba.r=t.r,this.rgba.g=t.g,this.rgba.b=t.b},setValue(t){let s=F.rgb2hsv(t.r,t.g,t.b),o=F.rgb2hsl(t.r,t.g,t.b);if(this.hsv="hsv("+s.h+","+s.s+","+s.v+")",this.hex="#"+F.rgbToHex(t),this.hsl="hsl("+o.h+","+o.s+","+o.l+")","hsv"==this.colorFormat){for(let t in s)"h"!=t&&(s[t]+="%");this.colorVal="hsv("+s.h+","+s.s+","+s.v+")"}else"hsl"==this.colorFormat?this.colorVal="hsl("+o.h+","+o.s+","+o.l+")":"rgba"==this.colorFormat?this.colorVal=this.colorFormat+"("+t.r+","+t.g+","+t.b+","+t.a+")":"rgb"==this.colorFormat?this.colorVal=this.colorFormat+"("+t.r+","+t.g+","+t.b+")":this.colorVal="#"+F.rgbToHex(t)},setControl(t,s){const{top:o,left:r,width:e,height:a}=this.position[t];1===t?(this.hsb.h=parseInt(360*s/e),this.bgcolor=F.HSBToRGB({h:this.hsb.h,s:100,b:100}),this.setColor()):this.rgba.a=(s/e).toFixed(1),this.setValue(this.rgba)},setColorBySelect(t){const{r:s,g:o,b:r,a:e}=t;let a={};a={r:s?parseInt(s):0,g:o?parseInt(o):0,b:r?parseInt(r):0,a:e||0},this.rgba=a,this.hsb=F.rgbToHsb(a),this.changeViewByHsb()},changeViewByHsb(){const[t,s,o]=this.position;this.site[0].left=parseInt(this.hsb.s*t.width/100),this.site[0].top=parseInt((100-this.hsb.b)*t.height/100),this.setColor(this.hsb.h),this.setValue(this.rgba),this.bgcolor=F.HSBToRGB({h:this.hsb.h,s:100,b:100}),this.site[1].left=this.hsb.h/360*s.width,"rgba"==this.colorFormat&&(this.site[2].left=this.rgba.a*o.width)},getSelectorQuery(){s().in(this).selectAll(".boxs").boundingClientRect((t=>{t&&0!==t.length?(this.position=t,this.setColorBySelect(this.rgba)):this.getSelectorQuery()})).exec()}}},[["render",function(t,s,v,_,x,C){const F=p;return o((e(),a(F,{class:"t-wrapper",onTouchmove:c(C.moveHandle,["stop","prevent"])},{default:h((()=>[i(F,{class:l(["t-mask",{active:x.active}]),onClick:c(C.close,["stop"])},null,8,["class","onClick"]),i(F,{class:l(["t-box",{active:x.active}])},{default:h((()=>[i(F,{class:"t-header"},{default:h((()=>[i(F,{class:"t-header-button",onClick:C.close},{default:h((()=>[n("取消")])),_:1},8,["onClick"]),i(F,{class:"t-header-button",onClick:C.confirm},{default:h((()=>[n("确认")])),_:1},8,["onClick"])])),_:1}),i(F,{class:"t-color__box",style:b({background:"rgb("+x.bgcolor.r+","+x.bgcolor.g+","+x.bgcolor.b+")"})},{default:h((()=>[i(F,{class:"t-background boxs",onTouchstart:s[0]||(s[0]=t=>C.touchstart(t,0)),onTouchmove:s[1]||(s[1]=t=>C.touchmove(t,0)),onTouchend:s[2]||(s[2]=t=>C.touchend(t,0))},{default:h((()=>[i(F,{class:"t-color-mask"}),i(F,{class:"t-pointer",style:b({top:x.site[0].top-8+"px",left:x.site[0].left-8+"px"})},null,8,["style"])])),_:1})])),_:1},8,["style"]),i(F,{class:"t-control__box"},{default:h((()=>["rgba"==v.colorFormat?(e(),a(F,{key:0,class:"t-control__color"},{default:h((()=>[i(F,{class:"t-control__color-content",style:b({background:"rgba("+x.rgba.r+","+x.rgba.g+","+x.rgba.b+","+x.rgba.a+")"})},null,8,["style"])])),_:1})):g("",!0),i(F,{class:"t-control-box__item"},{default:h((()=>[i(F,{class:"t-controller boxs",onTouchstart:s[3]||(s[3]=t=>C.touchstart(t,1)),onTouchmove:s[4]||(s[4]=t=>C.touchmove(t,1)),onTouchend:s[5]||(s[5]=t=>C.touchend(t,1))},{default:h((()=>[i(F,{class:"t-hue"},{default:h((()=>[i(F,{class:"t-circle",style:b({left:x.site[1].left-12+"px"})},null,8,["style"])])),_:1})])),_:1}),"rgba"==v.colorFormat?(e(),a(F,{key:0,class:"t-controller boxs",onTouchstart:s[6]||(s[6]=t=>C.touchstart(t,2)),onTouchmove:s[7]||(s[7]=t=>C.touchmove(t,2)),onTouchend:s[8]||(s[8]=t=>C.touchend(t,2))},{default:h((()=>[i(F,{class:"t-transparency"},{default:h((()=>[i(F,{class:"t-circle",style:b({left:x.site[2].left-12+"px"})},null,8,["style"])])),_:1})])),_:1})):g("",!0)])),_:1})])),_:1}),i(F,{class:"t-result__box"},{default:h((()=>[i(F,{class:"t-result__item"},{default:h((()=>[i(F,{class:"t-result__box-input"},{default:h((()=>[n(u(x.colorVal),1)])),_:1})])),_:1})])),_:1}),v.isCommonColor?(e(),a(F,{key:0,class:"t-alternative"},{default:h((()=>[(e(!0),d(m,null,f(x.conversion.colorList,((t,s)=>(e(),a(F,{class:"t-alternative__item",key:s},{default:h((()=>[i(F,{class:"t-alternative__item-content",style:b({background:"rgba("+t.r+","+t.g+","+t.b+","+t.a+")"}),onClick:s=>C.selectColor(t)},null,8,["style","onClick"])])),_:2},1024)))),128))])),_:1})):g("",!0)])),_:1},8,["class"])])),_:1},8,["onTouchmove"])),[[r,x.show]])}],["__scopeId","data-v-d2a2130c"]])},props:{modelValue:{default:""},colorFormat:{type:String,default:"hex"},disabled:{type:Boolean,default:!1}},data:()=>({bgColor:"#fff",hsvObj:{},hsvList:["h","s","v"],innerValue:""}),watch:{modelValue:{handler(t){this.innerValue=t,this.setDafault()},immediate:!0}},methods:{open(t){this.disabled||this.$refs.colorPicker.open()},confirm(t){this.bgColor=t.colorVal,this.$emit("update:modelValue",this.bgColor),this.$emit("change",this.bgColor)},setDafault(){if(!this.innerValue)return this.bgColor="#fff";this.$nextTick((()=>{if("hsv"===this.colorFormat){let t="";this.innerValue.match(/\(([^)]*)\)/)[1].split(",").forEach(((t,s)=>{this.$set(this[this.colorFormat+"Obj"],this[this.colorFormat+"List"][s],t)})),t=F.hsv2rgb(this[this.colorFormat+"Obj"].h,this[this.colorFormat+"Obj"].s,this[this.colorFormat+"Obj"].v),this.bgColor=`rgb(${t.r},${t.g},${t.b})`}else this.bgColor=this.innerValue}))}}},[["render",function(s,o,r,l,c,n){const g=x(v("uni-icons"),t),u=p,d=_("t-color-picker");return e(),a(u,{class:"jnpf-color-picker"},{default:h((()=>[i(u,{class:"color-box",onClick:n.open},{default:h((()=>[i(u,{class:"colorVal",style:b({backgroundColor:c.bgColor})},{default:h((()=>[i(g,{type:"bottom",size:"10",color:"#c7c7c7"})])),_:1},8,["style"])])),_:1},8,["onClick"]),i(d,{ref:"colorPicker",color:c.innerValue,onConfirm:n.confirm,colorFormat:r.colorFormat},null,8,["color","onConfirm","colorFormat"])])),_:1})}],["__scopeId","data-v-4de83a13"]]);export{k as _};