"use strict";(self.webpackChunkmulti_token_edit=self.webpackChunkmulti_token_edit||[]).push([[236],{5236:(t,e,i)=>{i.d(e,{ColorSlider:()=>ColorSlider});var s=i(149);i(5373);class ColorSlider{constructor(t,e){this.slider=t.find(".slide"),this.colors=e,this.min=0,this.max=100,this._init(),this._activateListeners(t)}_activateListeners(t){this.hue=t.find('[name="hue"]'),this.space=t.find('[name="space"]');const e=t.find('[name="method"]');this.hue.on("input",this.update.bind(this)),this.space.on("input",this.update.bind(this)),e.on("input",this.update.bind(this))}_init(){this._createSlider()}update(){clearTimeout(this.inputTimer),this.inputTimer=setTimeout(()=>this._updateSlider(),500)}_updateSlider(t,e){e&&(this.colors[e.handleIndex].offset=e.value),this.slider.find(".slide-back").remove();let i,s,r=this.max+1,l=this.slider.find("span").toArray();for(let t=0;t<l.length;t++){let e=this.slider.slider("values",t);if(this.colors[t].offset=e,e<r&&(i=$(this),r=e,s=t),$(l[t]).css("background",this.colors[t].hex),e!==this.max){let[i,s]=this._getNextColor(this.colors[t].hex,e);this._appendStrip(this._genGradient(i,this.colors[t].hex),s-e+"%",`${e}%`)}}r!==this.min&&this._appendStrip(this._genGradient(this.colors[s].hex,this.colors[s].hex),`${this.slider.slider("values",s)}%`,"0%")}_genGradient(t,e){const i=this.space?.val()||"lch";if("discrete"===i)return"rgba(0, 0, 0, 0)";const r=this.hue?.val()||"shorter";let l=s.default.range(e,t,{space:i,hue:r});return`linear-gradient(to right, ${s.default.steps(l,{steps:5,maxDeltaE:3}).map(t=>t.display()).join(", ")})`}_appendStrip(t,e,i){this.slider.append($("<div></div>").addClass("slide-back").width(e).css("background",t).css("left",i))}_getNextColor(t,e){let i=t,s=this.max+1;for(let t=0;t<this.colors.length;t++){let r=this.slider.slider("values",t);r>e&&r<s&&(i=this.colors[t].hex,s=r)}return[i,Math.min(s,this.max)]}_onCreateSlider(){let t=this.slider.find("span").toArray();for(let e=0;e<t.length;e++){let i=$(`<input type="color" value="${this.colors[e].hex}" style='opacity:0;width:100%;height:100%;position:absolute;pointer-events:none;'>`);const s=$(t[e]);s.attr("handleindex",e),s.append(i),s.on("click",t=>{2===t.detail&&(t.preventDefault(),i.trigger("click"))}),i.on("input",t=>{this.colors[e].hex=i.val(),this.update()}),s.on("contextmenu",t=>{if(t.preventDefault(),t.stopPropagation(),this.colors.length>2){let e=t.target.getAttribute("handleindex");e&&(this.colors.splice(e,1),this._createSlider())}})}this.slider.on("contextmenu",t=>{let e=this.slider.offset();var i=t.clientX-e.left;let s=Math.round(i/this.slider.width()*100);if(!this._percentExists(s)){let[t,e]=this._getNextColor(null,s);t||(t="#ff0000"),this.colors.push({hex:t,offset:s}),this._createSlider()}}),this.update()}_percentExists(t){return this.colors.some(e=>e.offset===t)}getColors(){return foundry.utils.deepClone(this.colors).sort((t,e)=>t.offset-e.offset)}_createSlider=()=>{this.slider.slider("instance")&&this.slider.slider("destroy"),this.slider.slider({change:(t,e)=>this.update(t,e),create:()=>this._onCreateSlider(),min:this.min,max:this.max,values:this.colors.map(t=>t.offset)})}}}}]);
//# sourceMappingURL=236.mass-edit.js.map