@rogieking/figui3 6.20.2 → 6.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,26 @@
1
- import"./fig.js";function B(Q){return String(Q??"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var D=["srgb","srgb-linear","display-p3","oklab","oklch"],G=["shorter","longer","increasing","decreasing"];function F(Q){let X={...Q??{}},Y=String(X.interpolationSpace??"srgb").toLowerCase();if(!D.includes(Y))Y="srgb";X.interpolationSpace=Y;let Z=String(X.hueInterpolation??"shorter").toLowerCase();return X.hueInterpolation=G.includes(Z)?Z:"shorter",X}function f(Q){let X=F(Q),Y={...X,interpolationSpace:X.interpolationSpace};if(X.interpolationSpace==="oklch")Y.hueInterpolation=X.hueInterpolation;else delete Y.hueInterpolation;return Y}function H(Q){let X=F(Q);if(X.interpolationSpace==="srgb")return"";if(X.interpolationSpace==="oklch")return`in oklch ${X.hueInterpolation} hue`;return`in ${X.interpolationSpace}`}class V extends HTMLElement{#$=null;#j=null;#Q=null;#S="solid";anchorElement=null;#O="solid";#q="srgb";#Y={h:0,s:0,v:85,a:1};#T="hex";#X={type:"linear",angle:0,centerX:50,centerY:50,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{position:0,color:"#D9D9D9",opacity:100},{position:100,color:"#737373",opacity:100}]};#J={url:null,scaleMode:"fill",scale:50};#K={url:null,scaleMode:"fill",scale:50};#W={stream:null,snapshot:null};#_={};#x={};#L=null;#k=null;#N=null;#F=null;#V=!1;#f=!1;#D=null;#y=null;#s=null;#A=0;#I=null;#v=null;constructor(){super();this.#I=this.#WQ.bind(this),this.#v=this.#UQ.bind(this)}static get observedAttributes(){return["value","disabled","alpha","mode","experimental","aria-label","aria-labelledby","aria-describedby"]}connectedCallback(){this.style.display="contents",requestAnimationFrame(()=>{this.#KQ(),this.#r(),this.#U()})}disconnectedCallback(){if(this.#a(),this.#W.snapshot?.startsWith("blob:")){if(URL.revokeObjectURL(this.#W.snapshot),this.#J.url===this.#W.snapshot)this.#J.url=null;this.#W.snapshot=null}if(this.#K.url&&this.#K.url.startsWith("blob:"))URL.revokeObjectURL(this.#K.url);if(this.#j)this.#j.removeAttribute("selected");if(this.#$)this.#$.removeEventListener("click",this.#I),this.#$.removeEventListener("keydown",this.#v)}#KQ(){let Q=Array.from(this.children).find((X)=>!X.getAttribute("slot")?.startsWith("mode-"));if(!Q)this.#j=document.createElement("fig-swatch"),this.#j.setAttribute("background","#D9D9D9"),this.appendChild(this.#j),this.#$=this.#j;else if(Q.matches("fig-swatch"))this.#j=Q,this.#$=Q;else this.#$=Q,this.#j=null;if(this.#w(),this.#$.removeEventListener("click",this.#I),this.#$.addEventListener("click",this.#I),this.#$.removeEventListener("keydown",this.#v),this.#$.addEventListener("keydown",this.#v),this.#j)requestAnimationFrame(()=>{let X=this.#j.querySelector('input[type="color"]');if(X)X.remove();this.#w()})}#n(){return this.getAttribute("aria-label")||"Fill picker"}#w(){if(!this.#$)return;let Q=this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false",X=this.getAttribute("aria-labelledby");if(!this.#$.hasAttribute("role"))this.#$.setAttribute("role","button");if(this.#$.setAttribute("tabindex",Q?"-1":"0"),this.#$.setAttribute("aria-disabled",Q?"true":"false"),X)this.#$.setAttribute("aria-labelledby",X),this.#$.removeAttribute("aria-label");else if(this.hasAttribute("aria-label"))this.#$.setAttribute("aria-label",`Open ${this.#n()}`),this.#$.removeAttribute("aria-labelledby");else if(this.#$.removeAttribute("aria-labelledby"),!this.#$.hasAttribute("aria-label"))this.#$.setAttribute("aria-label",`Open ${this.#n()}`);let Y=this.getAttribute("aria-describedby");if(Y)this.#$.setAttribute("aria-describedby",Y);else this.#$.removeAttribute("aria-describedby")}#WQ(Q){if(this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false")return;Q.stopPropagation(),Q.preventDefault(),this.#h()}#UQ(Q){if(Q.key!=="Enter"&&Q.key!==" ")return;if(this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false")return;Q.preventDefault(),Q.stopPropagation(),this.#h()}#r(){let Q=this.getAttribute("value");if(!Q)return;let X=["solid","gradient","image","video","webcam"];try{let Y=JSON.parse(Q);if(Y.type)this.#O=Y.type;if(Y.color){if(typeof Y.color==="string")this.#Y=this.#m(Y.color);else if(typeof Y.color==="object"&&Y.color.h!==void 0)this.#Y=Y.color}if(Y.opacity!==void 0)this.#Y.a=Y.opacity/100;if(Y.colorSpace==="display-p3"||Y.colorSpace==="srgb")this.#q=Y.colorSpace;if(Y.gradient)this.#X=F({...this.#X,...Y.gradient});if(Y.image)this.#J={...this.#J,...Y.image};if(Y.video)this.#K={...this.#K,...Y.video};if(Y.type&&!X.includes(Y.type)){let{type:Z,...$}=Y;this.#x[Y.type]=$}}catch(Y){if(Q.startsWith("#"))this.#O="solid",this.#Y=this.#m(Q)}}#U(){if(!this.#j)return;let Q,X="cover",Y="center";switch(this.#O){case"solid":Q=this.#B(this.#Y);break;case"gradient":Q=this.#ZQ();break;case"image":if(this.#J.url){Q=`url(${this.#J.url})`;let $=this.#o(this.#J.scaleMode,this.#J.scale);X=$.size,Y=$.position}else Q="";break;case"video":if(this.#K.url){Q=`url(${this.#K.url})`;let $=this.#o(this.#K.scaleMode,this.#K.scale);X=$.size,Y=$.position}else Q="";break;default:Q=this.#_[this.#O]?.element?.getAttribute("swatch-background")||"#D9D9D9"}if(this.#j.setAttribute("background",Q),this.#j.style.setProperty("--swatch-bg-size",X),this.#j.style.setProperty("--swatch-bg-position",Y),this.#O==="solid")this.#j.setAttribute("alpha",this.#Y.a);else this.#j.removeAttribute("alpha")}#o(Q,X){switch(Q){case"fill":return{size:"cover",position:"center"};case"fit":return{size:"contain",position:"center"};case"crop":return{size:"cover",position:"center"};case"tile":return{size:`${X}%`,position:"top left"};default:return{size:"cover",position:"center"}}}#h(){if(!this.#Q)this.#LQ();this.#y=JSON.stringify(this.value),this.#c(this.#O,{emit:!1});let Q=this.#Q.querySelector(".fig-fill-picker-gamut");if(Q)Q.value=this.#q;if(this.#j)this.#j.setAttribute("selected","true");this.#Q.open=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#H(),this.#z()})})}open(){this.#h()}close(){if(this.#Q)this.#Q.open=!1}#OQ(){if(!this.#Q)return;for(let[Q,{element:X}]of Object.entries(this.#_)){let Y=Array.from(this.#Q.querySelectorAll(".fig-fill-picker-tab")).find((Z)=>Z.dataset.tab===Q);if(!Y)continue;while(Y.firstChild)X.appendChild(Y.firstChild)}}#a(){if(this.#D)this.#D(),this.#D=null;if(this.#b(),!this.#Q)return;this.#OQ(),this.#Q.remove(),this.#Q=null,this.#s=null,this.#y=null}#b(){if(this.#A+=1,this.#W.stream)this.#W.stream.getTracks().forEach((X)=>X.stop()),this.#W.stream=null;let Q=this.#Q?.querySelector(".fig-fill-picker-webcam-video");if(Q)Q.srcObject=null}#LQ(){this.#_={},this.querySelectorAll('[slot^="mode-"]').forEach((q)=>{let z=q.getAttribute("slot").slice(5);this.#_[z]={element:q,label:q.getAttribute("label")||z.charAt(0).toUpperCase()+z.slice(1)}}),this.#Q=document.createElement("dialog",{is:"fig-popup"}),this.#Q.setAttribute("is","fig-popup"),this.#Q.setAttribute("drag","true"),this.#Q.setAttribute("handle","fig-header"),this.#Q.setAttribute("autoresize","false"),this.#Q.classList.add("fig-fill-picker-dialog"),this.#Q.anchor=this.anchorElement||this.#$;let Q=this.getAttribute("dialog-position")||"left";this.#Q.setAttribute("position",Q),this.#Q.setAttribute("offset",this.getAttribute("dialog-offset")||"8 8");let X=["solid","gradient","image","video","webcam"],Y={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},Z=this.getAttribute("mode"),$;if(Z){if($=Z.split(",").map((z)=>z.trim().toLowerCase()).filter((z)=>X.includes(z)||this.#_[z]),$.length===0)$=[...X]}else $=[...X];let j={...Y};for(let[q,{label:z}]of Object.entries(this.#_))j[q]=z;if(!$.includes(this.#O))this.#O=$[0],this.#S=$[0];let J=this.getAttribute("experimental"),K=J?`experimental="${B(J)}"`:"",O;if($.length===1)O=`<h3 class="fig-fill-picker-type-label">${B(j[$[0]])}</h3>`;else{let q=$.map((z)=>`<option value="${B(z)}">${B(j[z])}</option>`).join(`
2
- `);O=`<fig-dropdown class="fig-fill-picker-type" label="Fill type" ${K} value="${B(this.#O)}">
3
- ${q}
4
- </fig-dropdown>`}let W=$.map((q)=>`<div class="fig-fill-picker-tab" data-tab="${B(q)}"></div>`).join(`
5
- `),L=`<fig-dropdown class="fig-fill-picker-gamut" label="Color gamut" ${K} value="${this.#q}">
6
- <option value="srgb">sRGB</option>
7
- <option value="display-p3">Display P3</option>
8
- </fig-dropdown>`;this.#Q.innerHTML=`
1
+ import"./fig.js";import"./fig-lab.js";function C(j,J){if(!customElements.get(j))customElements.define(j,J)}function L(j){return String(j??"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var M=["srgb","srgb-linear","display-p3","oklab","oklch","hsl"],y=["shorter","longer","increasing","decreasing"],k=new Set(["oklch","hsl"]);function f(j){let J={...j??{}},K=String(J.interpolationSpace??"srgb").toLowerCase();if(!M.includes(K))K="srgb";J.interpolationSpace=K;let U=String(J.hueInterpolation??"shorter").toLowerCase();return J.hueInterpolation=y.includes(U)?U:"shorter",J}function D(j){let J=f(j),K={...J,interpolationSpace:J.interpolationSpace};if(k.has(J.interpolationSpace))K.hueInterpolation=J.hueInterpolation;else delete K.hueInterpolation;return K}function E(j){let J=f(j);if(J.interpolationSpace==="srgb")return"";if(k.has(J.interpolationSpace))return`in ${J.interpolationSpace} ${J.hueInterpolation} hue`;return`in ${J.interpolationSpace}`}function H(j){let J=f(j);if(k.has(J.interpolationSpace))return`${J.interpolationSpace}-${J.hueInterpolation||"shorter"}`;return J.interpolationSpace}function q(j){let J=String(j??"");for(let K of k){let U=`${K}-`;if(J.startsWith(U))return{interpolationSpace:K,hueInterpolation:J.slice(U.length)||"shorter"}}return{interpolationSpace:J||"srgb",hueInterpolation:"shorter"}}class F extends HTMLElement{#U=null;#Y=null;#j=null;#x="solid";anchorElement=null;#O="solid";#A="srgb";#K={h:0,s:0,v:85,a:1};#B="hex";#J={type:"linear",angle:0,centerX:50,centerY:50,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{position:0,color:"#D9D9D9",opacity:100},{position:100,color:"#737373",opacity:100}]};#X={url:null,scaleMode:"fill",scale:50};#Z={url:null,scaleMode:"fill",scale:50};#$={stream:null,snapshot:null};#R={};#v={};#T=null;#G=null;#_=null;#z=null;#q=!1;#L=!1;#H=null;#P=null;#S=null;#c=null;#I=0;#u=null;#g=null;constructor(){super();this.#u=this.#Oj.bind(this),this.#g=this.#Tj.bind(this)}static get observedAttributes(){return["value","disabled","alpha","mode","experimental","aria-label","aria-labelledby","aria-describedby"]}connectedCallback(){this.style.display="contents",requestAnimationFrame(()=>{this.#Wj(),this.#t(),this.#W()})}disconnectedCallback(){if(this.#jj(),this.#$.snapshot?.startsWith("blob:")){if(URL.revokeObjectURL(this.#$.snapshot),this.#X.url===this.#$.snapshot)this.#X.url=null;this.#$.snapshot=null}if(this.#Z.url&&this.#Z.url.startsWith("blob:"))URL.revokeObjectURL(this.#Z.url);if(this.#Y)this.#Y.removeAttribute("selected");if(this.#U)this.#U.removeEventListener("click",this.#u),this.#U.removeEventListener("keydown",this.#g)}#Wj(){let j=Array.from(this.children).find((J)=>!J.getAttribute("slot")?.startsWith("mode-"));if(!j)this.#Y=document.createElement("fig-swatch"),this.#Y.setAttribute("background","#D9D9D9"),this.appendChild(this.#Y),this.#U=this.#Y;else if(j.matches("fig-swatch"))this.#Y=j,this.#U=j;else this.#U=j,this.#Y=null;if(this.#b(),this.#U.removeEventListener("click",this.#u),this.#U.addEventListener("click",this.#u),this.#U.removeEventListener("keydown",this.#g),this.#U.addEventListener("keydown",this.#g),this.#Y)requestAnimationFrame(()=>{let J=this.#Y.querySelector('input[type="color"]');if(J)J.remove();this.#b()})}#a(){return this.getAttribute("aria-label")||"Fill picker"}#b(){if(!this.#U)return;let j=this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false",J=this.getAttribute("aria-labelledby");if(!this.#U.hasAttribute("role"))this.#U.setAttribute("role","button");if(this.#U.setAttribute("tabindex",j?"-1":"0"),this.#U.setAttribute("aria-disabled",j?"true":"false"),J)this.#U.setAttribute("aria-labelledby",J),this.#U.removeAttribute("aria-label");else if(this.hasAttribute("aria-label"))this.#U.setAttribute("aria-label",`Open ${this.#a()}`),this.#U.removeAttribute("aria-labelledby");else if(this.#U.removeAttribute("aria-labelledby"),!this.#U.hasAttribute("aria-label"))this.#U.setAttribute("aria-label",`Open ${this.#a()}`);let K=this.getAttribute("aria-describedby");if(K)this.#U.setAttribute("aria-describedby",K);else this.#U.removeAttribute("aria-describedby")}#Oj(j){if(this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false")return;j.stopPropagation(),j.preventDefault(),this.#h()}#Tj(j){if(j.key!=="Enter"&&j.key!==" ")return;if(this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false")return;j.preventDefault(),j.stopPropagation(),this.#h()}#t(){let j=this.getAttribute("value");if(!j)return;let J=["solid","gradient","image","video","webcam"];try{let K=JSON.parse(j);if(K.type)this.#O=K.type;if(K.color){if(typeof K.color==="string")this.#K=this.#E(K.color);else if(typeof K.color==="object"&&K.color.h!==void 0)this.#K=K.color}if(K.opacity!==void 0)this.#K.a=K.opacity/100;if(this.#A="srgb",K.gradient)this.#J=f({...this.#J,...K.gradient});if(K.image)this.#X={...this.#X,...K.image};if(K.video)this.#Z={...this.#Z,...K.video};if(K.type&&!J.includes(K.type)){let{type:U,...Q}=K;this.#v[K.type]=Q}}catch(K){if(j.startsWith("#"))this.#O="solid",this.#K=this.#E(j)}}#W(){if(!this.#Y)return;let j,J="cover",K="center";switch(this.#O){case"solid":j=this.#V(this.#K);break;case"gradient":j=this.#Yj();break;case"image":if(this.#X.url){j=`url(${this.#X.url})`;let Q=this.#e(this.#X.scaleMode,this.#X.scale);J=Q.size,K=Q.position}else j="";break;case"video":if(this.#Z.url){j=`url(${this.#Z.url})`;let Q=this.#e(this.#Z.scaleMode,this.#Z.scale);J=Q.size,K=Q.position}else j="";break;default:j=this.#R[this.#O]?.element?.getAttribute("swatch-background")||"#D9D9D9"}if(this.#Y.setAttribute("background",j),this.#Y.style.setProperty("--swatch-bg-size",J),this.#Y.style.setProperty("--swatch-bg-position",K),this.#O==="solid")this.#Y.setAttribute("alpha",this.#K.a);else this.#Y.removeAttribute("alpha")}#e(j,J){switch(j){case"fill":return{size:"cover",position:"center"};case"fit":return{size:"contain",position:"center"};case"crop":return{size:"cover",position:"center"};case"tile":return{size:`${J}%`,position:"top left"};default:return{size:"cover",position:"center"}}}#h(){if(!this.#j)this.#zj();if(this.#S=JSON.stringify(this.value),this.#s(this.#O,{emit:!1}),this.#Y)this.#Y.setAttribute("selected","true");this.#j.open=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#N(),this.#f()})})}open(){this.#h()}close(){if(this.#j)this.#j.open=!1}#Rj(){if(!this.#j)return;for(let[j,{element:J}]of Object.entries(this.#R)){let K=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((U)=>U.dataset.tab===j);if(!K)continue;while(K.firstChild)J.appendChild(K.firstChild)}}#jj(){if(this.#H)this.#H(),this.#H=null;if(this.#P?.disconnect(),this.#P=null,this.#m(),!this.#j)return;this.#Rj(),this.#j.remove(),this.#j=null,this.#c=null,this.#S=null}#m(){if(this.#I+=1,this.#$.stream)this.#$.stream.getTracks().forEach((J)=>J.stop()),this.#$.stream=null;let j=this.#j?.querySelector(".fig-fill-picker-webcam-video");if(j)j.srcObject=null}#zj(){this.#R={},this.querySelectorAll('[slot^="mode-"]').forEach((Y)=>{let W=Y.getAttribute("slot").slice(5);this.#R[W]={element:Y,label:Y.getAttribute("label")||W.charAt(0).toUpperCase()+W.slice(1)}}),this.#j=document.createElement("dialog",{is:"fig-popup"}),this.#j.setAttribute("is","fig-popup"),this.#j.setAttribute("drag","true"),this.#j.setAttribute("handle","fig-header"),this.#j.setAttribute("autoresize","false"),this.#j.classList.add("fig-fill-picker-dialog"),this.#j.anchor=this.anchorElement||this.#U;let j=this.getAttribute("dialog-position")||"left";this.#j.setAttribute("position",j),this.#j.setAttribute("offset",this.getAttribute("dialog-offset")||"8 8");let J=["solid","gradient","image","video","webcam"],K={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},U=this.getAttribute("mode"),Q;if(U){if(Q=U.split(",").map((W)=>W.trim().toLowerCase()).filter((W)=>J.includes(W)||this.#R[W]),Q.length===0)Q=[...J]}else Q=[...J];let X={...K};for(let[Y,{label:W}]of Object.entries(this.#R))X[Y]=W;if(!Q.includes(this.#O))this.#O=Q[0],this.#x=Q[0];let Z;if(Q.length===1)Z=`<h3 class="fig-fill-picker-type-label">${L(X[Q[0]])}</h3>`;else{let Y=Q.map((W)=>`<fig-select-option value="${L(W)}">${L(X[W])}</fig-select-option>`).join(`
2
+ `);Z=`<fig-select class="fig-fill-picker-type" label="Fill type" value="${L(this.#O)}">
3
+ <fig-select-options>
4
+ ${Y}
5
+ </fig-select-options>
6
+ </fig-select>`}let $=Q.map((Y)=>`<div class="fig-fill-picker-tab" data-tab="${L(Y)}"></div>`).join(`
7
+ `);this.#j.innerHTML=`
9
8
  <fig-header>
10
- ${O}
11
- ${L}
9
+ ${Z}
12
10
  <fig-button icon variant="ghost" class="fig-fill-picker-close" aria-label="Close fill picker">
13
11
  <fig-icon name="close"></fig-icon>
14
12
  </fig-button>
15
13
  </fig-header>
16
14
  <fig-content>
17
- ${W}
15
+ ${$}
18
16
  </fig-content>
19
- `,document.body.appendChild(this.#Q);for(let[q,{element:z}]of Object.entries(this.#_)){let k=Array.from(this.#Q.querySelectorAll(".fig-fill-picker-tab")).find((N)=>N.dataset.tab===q);if(!k)continue;while(z.firstChild)k.appendChild(z.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:q,container:k}}))}let U=this.#Q.querySelector(".fig-fill-picker-type");if(U)U.addEventListener("change",(q)=>{this.#c(q.target.value)});let _=this.#Q.querySelector(".fig-fill-picker-gamut");if(_){let q=(z)=>{let k=z.currentTarget?.value??z.target?.value??z.detail;if(k&&k!==this.#q)this.#q=k,this.#qQ()};_.addEventListener("change",q)}this.#Q.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#Q.open=!1});let M=()=>{if(this.#j)this.#j.removeAttribute("selected");if(this.#b(),this.#y!==null&&this.#y!==JSON.stringify(this.value))this.#M();this.#y=null,this.dispatchEvent(new CustomEvent("close"))};this.#Q.addEventListener("close",M);let R={solid:()=>this.#_Q(),gradient:()=>this.#kQ(),image:()=>this.#DQ(),video:()=>this.#HQ(),webcam:()=>this.#PQ()};for(let[q,z]of Object.entries(R))if(!this.#_[q]&&$.includes(q))z();for(let q of Object.keys(this.#_)){if(X.includes(q))continue;let z=Array.from(this.#Q.querySelectorAll(".fig-fill-picker-tab")).find((k)=>k.dataset.tab===q);if(!z)continue;z.addEventListener("input",(k)=>{if(k.target===this)return;if(k.stopPropagation(),k.detail)this.#x[q]=k.detail;this.#Z()}),z.addEventListener("change",(k)=>{if(k.target===this)return;if(k.stopPropagation(),k.detail)this.#x[q]=k.detail;this.#M()})}}#c(Q,{emit:X=!0}={}){let Y=Array.from(this.#Q?.querySelectorAll(".fig-fill-picker-tab")??[]).find((K)=>K.dataset.tab===Q);if(!Y)return;let Z=this.#S;if(this.#S=Q,this.#O=Q,Z==="webcam"&&Q!=="webcam")this.#b();let $=this.#Q.querySelector(".fig-fill-picker-type");if($&&$.value!==Q)$.value=Q;this.#Q.querySelectorAll(".fig-fill-picker-tab").forEach((K)=>{if(K.dataset.tab===Q)K.style.display="block";else K.style.display="none"});let J=this.#Q.querySelector("fig-content");if(J)J.style.padding=this.#_[Q]?"0":"";if(Q==="gradient")requestAnimationFrame(()=>{this.#G();let K=Y.querySelector(".fig-fill-picker-gradient-bar-input");K?.refreshLayout?.(),requestAnimationFrame(()=>{K?.refreshLayout?.()})});if(Q==="webcam")this.#s?.();if(this.#U(),X)this.#Z()}#_Q(){let Q=this.#Q.querySelector('[data-tab="solid"]'),X=this.getAttribute("alpha")!=="false",Y=this.getAttribute("experimental"),Z=Y?`experimental="${Y}"`:"";if(Q.innerHTML=`
17
+ `,document.body.appendChild(this.#j);for(let[Y,{element:W}]of Object.entries(this.#R)){let z=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((G)=>G.dataset.tab===Y);if(!z)continue;while(W.firstChild)z.appendChild(W.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:Y,container:z}}))}let T=this.#j.querySelector(".fig-fill-picker-type");if(T)T.addEventListener("change",(Y)=>{let W=typeof Y.detail==="string"?Y.detail:Y.target?.value;if(W)this.#s(W)});this.#j.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#j.open=!1});let O=()=>{if(this.#Y)this.#Y.removeAttribute("selected");if(this.#m(),this.#S!==null&&this.#S!==JSON.stringify(this.value))this.#k();this.#S=null,this.dispatchEvent(new CustomEvent("close"))};this.#j.addEventListener("close",O);let R={solid:()=>this.#Lj(),gradient:()=>this.#Dj(),image:()=>this.#Mj(),video:()=>this.#Ej(),webcam:()=>this.#Pj()};for(let[Y,W]of Object.entries(R))if(!this.#R[Y]&&Q.includes(Y))W();for(let Y of Object.keys(this.#R)){if(J.includes(Y))continue;let W=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((z)=>z.dataset.tab===Y);if(!W)continue;W.addEventListener("input",(z)=>{if(z.target===this)return;if(z.stopPropagation(),z.detail)this.#v[Y]=z.detail;this.#Q()}),W.addEventListener("change",(z)=>{if(z.target===this)return;if(z.stopPropagation(),z.detail)this.#v[Y]=z.detail;this.#k()})}}#s(j,{emit:J=!0}={}){let K=Array.from(this.#j?.querySelectorAll(".fig-fill-picker-tab")??[]).find(($)=>$.dataset.tab===j);if(!K)return;let U=this.#x;if(this.#x=j,this.#O=j,U==="webcam"&&j!=="webcam")this.#m();let Q=this.#j.querySelector(".fig-fill-picker-type");if(Q&&Q.value!==j)Q.value=j;this.#j.querySelectorAll(".fig-fill-picker-tab").forEach(($)=>{if($.dataset.tab===j)$.style.display="block";else $.style.display="none"});let Z=this.#j.querySelector("fig-content");if(Z)Z.style.padding=this.#R[j]?"0":"";if(j==="gradient")requestAnimationFrame(()=>{this.#D();let $=K.querySelector(".fig-fill-picker-gradient-bar-input");$?.refreshLayout?.(),requestAnimationFrame(()=>{$?.refreshLayout?.()})});if(j==="webcam")this.#c?.();if(this.#W(),J)this.#Q()}#Lj(){let j=this.#j.querySelector('[data-tab="solid"]'),J=this.getAttribute("alpha")!=="false";if(j.innerHTML=`
20
18
  <fig-preview class="fig-fill-picker-color-area">
21
19
  <canvas width="200" height="200"></canvas>
22
20
  <fig-handle
23
21
  aria-label="Color saturation and brightness"
24
22
  type="color"
25
- color="${this.#B({...this.#Y,a:1})}"
23
+ color="${this.#V({...this.#K,a:1})}"
26
24
  data-no-color-picker
27
25
  drag
28
26
  drag-surface=".fig-fill-picker-color-area"
@@ -30,64 +28,84 @@ import"./fig.js";function B(Q){return String(Q??"").replace(/&/g,"&amp;").replac
30
28
  drag-snapping="modifier"
31
29
  ></fig-handle>
32
30
  </fig-preview>
33
- <div class="fig-fill-picker-sliders">
31
+ <div class="fig-fill-picker-sliders${J?"":" is-hue-only"}">
34
32
  <fig-tooltip text="Sample color"><fig-button icon variant="ghost" class="fig-fill-picker-eyedropper" aria-label="Sample color"><fig-icon name="eyedropper"></fig-icon></fig-button></fig-tooltip>
35
- <fig-slider type="hue" text="false" min="0" max="360" aria-label="Hue" value="${this.#Y.h}"></fig-slider>
36
- ${X?`<fig-slider type="opacity" text="true" units="%" min="0" max="100" aria-label="Opacity" value="${this.#Y.a*100}" color="${this.#B(this.#Y)}"></fig-slider>`:""}
33
+ <fig-slider type="hue" variant="classic" text="false" min="0" max="360" aria-label="Hue" value="${this.#K.h}"></fig-slider>
34
+ ${J?`<fig-slider type="opacity" variant="classic" text="false" min="0" max="100" aria-label="Opacity" value="${this.#K.a*100}" color="${this.#V(this.#K)}"></fig-slider>`:""}
37
35
  </div>
38
36
  <fig-field class="fig-fill-picker-inputs">
39
- <fig-dropdown class="fig-fill-picker-input-mode" label="Color value format" ${Z} value="${this.#T}">
40
- <option value="hex">Hex</option>
41
- <option value="rgb">RGB</option>
42
- <option value="hsl">HSL</option>
43
- <option value="hsb">HSB</option>
44
- <option value="lab">LAB</option>
45
- <option value="lch">LCH</option>
46
- </fig-dropdown>
37
+ <fig-select class="fig-fill-picker-input-mode" label="Color value format" value="${L(this.#B)}">
38
+ <fig-select-options>
39
+ <fig-select-option value="hex">Hex</fig-select-option>
40
+ <fig-select-option value="rgb">RGB</fig-select-option>
41
+ <fig-select-option value="css">CSS</fig-select-option>
42
+ <fig-select-option value="hsl">HSL</fig-select-option>
43
+ <fig-select-option value="hsb">HSB</fig-select-option>
44
+ <fig-select-option value="lab">LAB</fig-select-option>
45
+ <fig-select-option value="lch">LCH</fig-select-option>
46
+ </fig-select-options>
47
+ </fig-select>
47
48
  <span class="fig-fill-picker-input-fields"></span>
48
49
  </fig-field>
49
- `,this.#L=Q.querySelector("canvas"),this.#k=Q.querySelector("fig-handle"),this.#H(),this.#z(),this.#t(),this.#N=Q.querySelector('fig-slider[type="hue"]'),this.#N.addEventListener("input",(J)=>{this.#Y.h=parseFloat(J.target.value),this.#H(),this.#z(),this.#E(),this.#Z()}),this.#N.addEventListener("change",()=>{this.#M()}),X)this.#F=Q.querySelector('fig-slider[type="opacity"]'),this.#F.addEventListener("input",(J)=>{this.#Y.a=parseFloat(J.target.value)/100,this.#E(),this.#Z()}),this.#F.addEventListener("change",()=>{this.#M()});Q.querySelector(".fig-fill-picker-input-mode").addEventListener("change",(J)=>{this.#T=J.target.value,this.#e()}),this.#e();let j=Q.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)j.addEventListener("click",async()=>{try{let K=await new EyeDropper().open();this.#Y={...this.#m(K.sRGBHex),a:this.#Y.a},this.#H(),this.#z(),this.#E(),this.#Z()}catch(J){}});else j.setAttribute("disabled",""),j.title="EyeDropper not supported in this browser"}#qQ(){let Q=this.#Q?.querySelector('[data-tab="solid"]');if(Q){let X=Q.querySelector("canvas");if(X){let Y=document.createElement("canvas");Y.width=X.width,Y.height=X.height,X.replaceWith(Y),this.#L=Y,this.#t()}this.#H(),this.#z()}this.#R(),this.#Z()}#H(){if(!this.#L&&this.#Q)this.#L=this.#Q.querySelector('[data-tab="solid"] canvas');if(!this.#L)return;let Q=this.#q==="display-p3"?"display-p3":"srgb",X=this.#L.getContext("2d",{colorSpace:Q});if(!X)return;let Y=this.#L.width,Z=this.#L.height;X.clearRect(0,0,Y,Z);let $=this.#Y.h,j=this.#q==="display-p3",J=X.createLinearGradient(0,0,Y,0);if(j){J.addColorStop(0,"color(display-p3 1 1 1)");let[O,W,L]=hslToP3($,100,50);J.addColorStop(1,`color(display-p3 ${O} ${W} ${L})`)}else J.addColorStop(0,"#FFFFFF"),J.addColorStop(1,`hsl(${$}, 100%, 50%)`);X.fillStyle=J,X.fillRect(0,0,Y,Z);let K=X.createLinearGradient(0,0,0,Z);K.addColorStop(0,"rgba(0,0,0,0)"),K.addColorStop(1,"rgba(0,0,0,1)"),X.fillStyle=K,X.fillRect(0,0,Y,Z)}#z(Q=0){if(!this.#k||!this.#L)return;let X=this.#L.getBoundingClientRect();if((X.width===0||X.height===0)&&Q<5){requestAnimationFrame(()=>this.#z(Q+1));return}let Y=Math.max(0,Math.min(100,this.#Y.s)),Z=Math.max(0,Math.min(100,100-this.#Y.v));this.#k.setAttribute("value",`${Y}% ${Z}%`),this.#k.setAttribute("color",this.#B({...this.#Y,a:1}))}#g(Q,X,Y={}){let{updateHandle:Z=!0,emitInput:$=!0,emitChange:j=!1}=Y;if(this.#Y.s=Math.max(0,Math.min(100,Q*100)),this.#Y.v=Math.max(0,Math.min(100,(1-X)*100)),this.#k)this.#k.setAttribute("color",this.#B({...this.#Y,a:1}));if(Z)this.#z();if(this.#E(),$)this.#Z();if(j)this.#M()}#t(){if(this.#D)this.#D(),this.#D=null;if(!this.#L||!this.#k)return;let Q=this.#L.parentElement||this.#L,X=this.#k,Y=!1,Z=(W,L={})=>{let U=Q.getBoundingClientRect();if(U.width===0||U.height===0)return;let _=Math.max(0,Math.min(W.clientX-U.left,U.width)),M=Math.max(0,Math.min(W.clientY-U.top,U.height));this.#g(_/U.width,M/U.height,L)},$=(W)=>{if(W.button!==0)return;if(W.target===X||X.contains(W.target))return;Y=!0,this.#V=!0,Q.setPointerCapture(W.pointerId),Z(W,{updateHandle:!0,emitInput:!0})},j=(W)=>{if(!Y)return;if(W.buttons===0){J();return}Z(W,{updateHandle:!0,emitInput:!0})},J=()=>{if(!Y)return;Y=!1,this.#V=!1,this.#M()},K=(W)=>{this.#V=!0;let L=W.detail?.px,U=W.detail?.py;if(!Number.isFinite(L)||!Number.isFinite(U))return;X.setAttribute("value",`${L*100}% ${U*100}%`),this.#g(L,U,{updateHandle:!1,emitInput:!0})},O=(W)=>{let L=W.detail?.px,U=W.detail?.py;if(Number.isFinite(L)&&Number.isFinite(U))X.setAttribute("value",`${L*100}% ${U*100}%`),this.#g(L,U,{updateHandle:!1,emitInput:!1});this.#V=!1,this.#M()};Q.addEventListener("pointerdown",$),Q.addEventListener("pointermove",j),Q.addEventListener("pointerup",J),Q.addEventListener("pointercancel",J),Q.addEventListener("lostpointercapture",J),X.addEventListener("input",K),X.addEventListener("change",O),this.#D=()=>{Q.removeEventListener("pointerdown",$),Q.removeEventListener("pointermove",j),Q.removeEventListener("pointerup",J),Q.removeEventListener("pointercancel",J),Q.removeEventListener("lostpointercapture",J),X.removeEventListener("input",K),X.removeEventListener("change",O),this.#V=!1}}#e(){let Q=this.#Q?.querySelector(".fig-fill-picker-input-fields");if(!Q)return;let X=($,j)=>`<fig-tooltip text="${$}">${j}</fig-tooltip>`,Y=($,j,J,K,O)=>`<fig-input-number class="${$}" aria-label="${j}" min="${J}" max="${K}"${O!=null?` step="${O}"`:""}></fig-input-number>`,Z;switch(this.#T){case"rgb":Z=`<div class="input-combo">
50
- ${X("Red",Y("fig-fill-picker-ci-r","Red",0,255))}
51
- ${X("Green",Y("fig-fill-picker-ci-g","Green",0,255))}
52
- ${X("Blue",Y("fig-fill-picker-ci-b","Blue",0,255))}
53
- </div>`;break;case"hsl":Z=`<div class="input-combo">
54
- ${X("Hue",Y("fig-fill-picker-ci-h","Hue",0,360))}
55
- ${X("Saturation",Y("fig-fill-picker-ci-s","Saturation",0,100))}
56
- ${X("Lightness",Y("fig-fill-picker-ci-l","Lightness",0,100))}
57
- </div>`;break;case"hsb":Z=`<div class="input-combo">
58
- ${X("Hue",Y("fig-fill-picker-ci-h","Hue",0,360))}
59
- ${X("Saturation",Y("fig-fill-picker-ci-s","Saturation",0,100))}
60
- ${X("Brightness",Y("fig-fill-picker-ci-v","Brightness",0,100))}
61
- </div>`;break;case"lab":Z=`<div class="input-combo">
62
- ${X("Lightness",Y("fig-fill-picker-ci-okl","Lightness",0,100))}
63
- ${X("Green-Red axis",Y("fig-fill-picker-ci-oka","Green-Red axis",-0.4,0.4,0.001))}
64
- ${X("Blue-Yellow axis",Y("fig-fill-picker-ci-okb","Blue-Yellow axis",-0.4,0.4,0.001))}
65
- </div>`;break;case"lch":Z=`<div class="input-combo">
66
- ${X("Lightness",Y("fig-fill-picker-ci-okl","Lightness",0,100))}
67
- ${X("Chroma",Y("fig-fill-picker-ci-okc","Chroma",0,0.4,0.001))}
68
- ${X("Hue",Y("fig-fill-picker-ci-okh","Hue",0,360))}
69
- </div>`;break;default:Z='<fig-input-text class="fig-fill-picker-ci-hex" aria-label="Hex color" placeholder="FFFFFF"></fig-input-text>';break}Q.innerHTML=Z,this.#zQ(),requestAnimationFrame(()=>this.#E())}#zQ(){let Q=this.#Q?.querySelector(".fig-fill-picker-input-fields");if(!Q)return;let X=()=>{if(this.#V)return;let $=this.#MQ();if(!$)return;if(this.#Y={...$,a:this.#Y.a},this.#H(),this.#z(),this.#N)this.#N.setAttribute("value",this.#Y.h);this.#Z()},Y=()=>this.#M();Q.querySelectorAll("fig-input-number, fig-input-text").forEach(($)=>{$.addEventListener("input",X),$.addEventListener("change",Y)})}#MQ(){let Q=(Y)=>this.#Q?.querySelector(`.${Y}`),X=(Y)=>parseFloat(Q(Y)?.value??0);switch(this.#T){case"rgb":return this.#C({r:X("fig-fill-picker-ci-r"),g:X("fig-fill-picker-ci-g"),b:X("fig-fill-picker-ci-b")});case"hsl":{let Y=this.#SQ({h:X("fig-fill-picker-ci-h"),s:X("fig-fill-picker-ci-s"),l:X("fig-fill-picker-ci-l")});return this.#C(Y)}case"hsb":return{h:X("fig-fill-picker-ci-h"),s:X("fig-fill-picker-ci-s"),v:X("fig-fill-picker-ci-v"),a:1};case"lab":{let Y=this.#jQ({l:X("fig-fill-picker-ci-okl")/100,a:X("fig-fill-picker-ci-oka"),b:X("fig-fill-picker-ci-okb")});return this.#C(Y)}case"lch":{let Y=this.#IQ({l:X("fig-fill-picker-ci-okl")/100,c:X("fig-fill-picker-ci-okc"),h:X("fig-fill-picker-ci-okh")});return this.#C(Y)}default:{let Y=Q("fig-fill-picker-ci-hex");if(!Y)return null;let Z=Y.value.replace(/^#/,"");if(Z.length===3)Z=Z[0]+Z[0]+Z[1]+Z[1]+Z[2]+Z[2];if(Z.length!==6||!/^[0-9a-fA-F]{6}$/.test(Z))return null;return this.#m(`#${Z}`)}}}#E(){if(!this.#Q)return;let Q=this.#B(this.#Y),X=this.#$Q(this.#Y),Y=($)=>this.#Q.querySelector(`.${$}`),Z=($,j)=>{let J=Y($);if(J)J.setAttribute("value",j)};switch(this.#T){case"rgb":Z("fig-fill-picker-ci-r",X.r),Z("fig-fill-picker-ci-g",X.g),Z("fig-fill-picker-ci-b",X.b);break;case"hsl":{let $=this.#CQ(X);Z("fig-fill-picker-ci-h",Math.round($.h)),Z("fig-fill-picker-ci-s",Math.round($.s)),Z("fig-fill-picker-ci-l",Math.round($.l));break}case"hsb":Z("fig-fill-picker-ci-h",Math.round(this.#Y.h)),Z("fig-fill-picker-ci-s",Math.round(this.#Y.s)),Z("fig-fill-picker-ci-v",Math.round(this.#Y.v));break;case"lab":{let $=this.#JQ(X);Z("fig-fill-picker-ci-okl",Math.round($.l*100)),Z("fig-fill-picker-ci-oka",+$.a.toFixed(3)),Z("fig-fill-picker-ci-okb",+$.b.toFixed(3));break}case"lch":{let $=this.#xQ(X);Z("fig-fill-picker-ci-okl",Math.round($.l*100)),Z("fig-fill-picker-ci-okc",+$.c.toFixed(3)),Z("fig-fill-picker-ci-okh",Math.round($.h));break}default:Z("fig-fill-picker-ci-hex",Q.replace(/^#/,"").toUpperCase());break}if(this.#F)this.#F.setAttribute("color",Q);this.#U()}#kQ(){let Q=this.#Q.querySelector('[data-tab="gradient"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
50
+ `,this.#T=j.querySelector("canvas"),this.#G=j.querySelector("fig-handle"),this.#N(),this.#f(),this.#Jj(),this.#_=j.querySelector('fig-slider[type="hue"]'),this.#_.addEventListener("input",(Q)=>{this.#K.h=parseFloat(Q.target.value),this.#N(),this.#f(),this.#C(),this.#Q()}),this.#_.addEventListener("change",()=>{this.#k()}),J)this.#z=j.querySelector('fig-slider[type="opacity"]'),this.#z.addEventListener("input",(Q)=>{this.#K.a=parseFloat(Q.target.value)/100,this.#C(),this.#Q()}),this.#z.addEventListener("change",()=>{this.#k()});j.querySelector(".fig-fill-picker-input-mode").addEventListener("change",(Q)=>{let X=typeof Q.detail==="string"?Q.detail:Q.target?.value;if(!X)return;this.#B=X,this.#Kj()}),this.#Kj();let U=j.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)U.addEventListener("click",async()=>{try{let X=await new EyeDropper().open();this.#K={...this.#E(X.sRGBHex),a:this.#K.a},this.#N(),this.#f(),this.#C(),this.#Q()}catch(Q){}});else U.setAttribute("disabled",""),U.title="EyeDropper not supported in this browser"}#dj(){let j=this.#j?.querySelector('[data-tab="solid"]');if(j){let J=j.querySelector("canvas");if(J){let K=document.createElement("canvas");K.width=J.width,K.height=J.height,J.replaceWith(K),this.#T=K,this.#Jj()}this.#N(),this.#f()}this.#F(),this.#Q()}#N(){if(!this.#T&&this.#j)this.#T=this.#j.querySelector('[data-tab="solid"] canvas');if(!this.#T)return;let j=this.#A==="display-p3"?"display-p3":"srgb",J=this.#T.getContext("2d",{colorSpace:j});if(!J)return;let K=this.#T.width,U=this.#T.height;J.clearRect(0,0,K,U);let Q=this.#K.h,X=this.#A==="display-p3",Z=J.createLinearGradient(0,0,K,0);if(X){Z.addColorStop(0,"color(display-p3 1 1 1)");let[T,O,R]=hslToP3(Q,100,50);Z.addColorStop(1,`color(display-p3 ${T} ${O} ${R})`)}else Z.addColorStop(0,"#FFFFFF"),Z.addColorStop(1,`hsl(${Q}, 100%, 50%)`);J.fillStyle=Z,J.fillRect(0,0,K,U);let $=J.createLinearGradient(0,0,0,U);$.addColorStop(0,"rgba(0,0,0,0)"),$.addColorStop(1,"rgba(0,0,0,1)"),J.fillStyle=$,J.fillRect(0,0,K,U)}#f(j=0){if(!this.#G||!this.#T)return;let J=this.#T.getBoundingClientRect();if((J.width===0||J.height===0)&&j<5){requestAnimationFrame(()=>this.#f(j+1));return}let K=Math.max(0,Math.min(100,this.#K.s)),U=Math.max(0,Math.min(100,100-this.#K.v));this.#G.setAttribute("value",`${K}% ${U}%`),this.#G.setAttribute("color",this.#V({...this.#K,a:1}))}#p(j,J,K={}){let{updateHandle:U=!0,emitInput:Q=!0,emitChange:X=!1}=K;if(this.#K.s=Math.max(0,Math.min(100,j*100)),this.#K.v=Math.max(0,Math.min(100,(1-J)*100)),this.#G)this.#G.setAttribute("color",this.#V({...this.#K,a:1}));if(U)this.#f();if(this.#C(),Q)this.#Q();if(X)this.#k()}#Jj(){if(this.#H)this.#H(),this.#H=null;if(!this.#T||!this.#G)return;let j=this.#T.parentElement||this.#T,J=this.#G,K=!1,U=(O,R={})=>{let Y=j.getBoundingClientRect();if(Y.width===0||Y.height===0)return;let W=Math.max(0,Math.min(O.clientX-Y.left,Y.width)),z=Math.max(0,Math.min(O.clientY-Y.top,Y.height));this.#p(W/Y.width,z/Y.height,R)},Q=(O)=>{if(O.button!==0)return;if(O.target===J||J.contains(O.target))return;K=!0,this.#q=!0,j.setPointerCapture(O.pointerId),U(O,{updateHandle:!0,emitInput:!0})},X=(O)=>{if(!K)return;if(O.buttons===0){Z();return}U(O,{updateHandle:!0,emitInput:!0})},Z=()=>{if(!K)return;K=!1,this.#q=!1,this.#k()},$=(O)=>{this.#q=!0;let R=O.detail?.px,Y=O.detail?.py;if(!Number.isFinite(R)||!Number.isFinite(Y))return;J.setAttribute("value",`${R*100}% ${Y*100}%`),this.#p(R,Y,{updateHandle:!1,emitInput:!0})},T=(O)=>{let R=O.detail?.px,Y=O.detail?.py;if(Number.isFinite(R)&&Number.isFinite(Y))J.setAttribute("value",`${R*100}% ${Y*100}%`),this.#p(R,Y,{updateHandle:!1,emitInput:!1});this.#q=!1,this.#k()};j.addEventListener("pointerdown",Q),j.addEventListener("pointermove",X),j.addEventListener("pointerup",Z),j.addEventListener("pointercancel",Z),j.addEventListener("lostpointercapture",Z),J.addEventListener("input",$),J.addEventListener("change",T),this.#H=()=>{j.removeEventListener("pointerdown",Q),j.removeEventListener("pointermove",X),j.removeEventListener("pointerup",Z),j.removeEventListener("pointercancel",Z),j.removeEventListener("lostpointercapture",Z),J.removeEventListener("input",$),J.removeEventListener("change",T),this.#q=!1}}#Kj(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let J=(Z,$)=>`<fig-tooltip text="${Z}">${$}</fig-tooltip>`,K=(Z,$,T,O,R,Y)=>`<fig-input-number class="${Z}" aria-label="${$}" min="${T}" max="${O}"${R!=null?` step="${R}"`:""}${Y?` units="${Y}"`:""}></fig-input-number>`,U=this.getAttribute("alpha")!=="false",Q=()=>U?J("Alpha",K("fig-fill-picker-ci-a","Alpha",0,100,0.1,"%")):"",X;switch(this.#B){case"rgb":X=`<div class="input-combo">
51
+ ${J("Red",K("fig-fill-picker-ci-r","Red",0,255))}
52
+ ${J("Green",K("fig-fill-picker-ci-g","Green",0,255))}
53
+ ${J("Blue",K("fig-fill-picker-ci-b","Blue",0,255))}
54
+ ${Q()}
55
+ </div>`;break;case"hsl":X=`<div class="input-combo">
56
+ ${J("Hue",K("fig-fill-picker-ci-h","Hue",0,360))}
57
+ ${J("Saturation",K("fig-fill-picker-ci-s","Saturation",0,100))}
58
+ ${J("Lightness",K("fig-fill-picker-ci-l","Lightness",0,100))}
59
+ ${Q()}
60
+ </div>`;break;case"hsb":X=`<div class="input-combo">
61
+ ${J("Hue",K("fig-fill-picker-ci-h","Hue",0,360))}
62
+ ${J("Saturation",K("fig-fill-picker-ci-s","Saturation",0,100))}
63
+ ${J("Brightness",K("fig-fill-picker-ci-v","Brightness",0,100))}
64
+ ${Q()}
65
+ </div>`;break;case"lab":X=`<div class="input-combo">
66
+ ${J("Lightness",K("fig-fill-picker-ci-okl","Lightness",0,100))}
67
+ ${J("Green-Red axis",K("fig-fill-picker-ci-oka","Green-Red axis",-0.4,0.4,0.001))}
68
+ ${J("Blue-Yellow axis",K("fig-fill-picker-ci-okb","Blue-Yellow axis",-0.4,0.4,0.001))}
69
+ ${Q()}
70
+ </div>`;break;case"lch":X=`<div class="input-combo">
71
+ ${J("Lightness",K("fig-fill-picker-ci-okl","Lightness",0,100))}
72
+ ${J("Chroma",K("fig-fill-picker-ci-okc","Chroma",0,0.4,0.001))}
73
+ ${J("Hue",K("fig-fill-picker-ci-okh","Hue",0,360))}
74
+ ${Q()}
75
+ </div>`;break;case"css":X='<fig-input-text class="fig-fill-picker-ci-css" aria-label="CSS color" placeholder="rgba(0, 0, 0, 1)"></fig-input-text>';break;default:X=U?`<div class="input-combo fig-fill-picker-ci-hex-row">
76
+ <fig-input-text class="fig-fill-picker-ci-hex" aria-label="Hex color" placeholder="FFFFFF"></fig-input-text>
77
+ ${Q()}
78
+ </div>`:'<fig-input-text class="fig-fill-picker-ci-hex" aria-label="Hex color" placeholder="FFFFFF"></fig-input-text>';break}j.innerHTML=X,this.#fj(),requestAnimationFrame(()=>this.#C())}#fj(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let J=()=>{if(this.#q)return;let Q=this.#Gj();if(!Q)return;let X=Number.isFinite(Q.a)?Q.a:this.#K.a;if(this.#K={...Q,a:X},this.#N(),this.#f(),this.#_)this.#_.setAttribute("value",this.#K.h);if(this.#z&&Number.isFinite(Q.a))this.#z.setAttribute("value",this.#K.a*100);this.#Q()},K=()=>this.#k();j.querySelectorAll("fig-input-number, fig-input-text").forEach((Q)=>{Q.addEventListener("input",J),Q.addEventListener("change",K)})}#kj(){let j=this.#j?.querySelector(".fig-fill-picker-ci-a");if(!j)return;let J=parseFloat(j.value);if(!Number.isFinite(J))return;return Math.max(0,Math.min(1,J/100))}#Gj(){let j=(U)=>this.#j?.querySelector(`.${U}`),J=(U)=>parseFloat(j(U)?.value??0),K=(U)=>{if(!U)return null;let Q=this.#kj();return{...U,a:Q??U.a??this.#K.a}};switch(this.#B){case"rgb":return K(this.#y({r:J("fig-fill-picker-ci-r"),g:J("fig-fill-picker-ci-g"),b:J("fig-fill-picker-ci-b")}));case"hsl":{let U=this.#bj({h:J("fig-fill-picker-ci-h"),s:J("fig-fill-picker-ci-s"),l:J("fig-fill-picker-ci-l")});return K(this.#y(U))}case"hsb":return K({h:J("fig-fill-picker-ci-h"),s:J("fig-fill-picker-ci-s"),v:J("fig-fill-picker-ci-v")});case"lab":{let U=this.#$j({l:J("fig-fill-picker-ci-okl")/100,a:J("fig-fill-picker-ci-oka"),b:J("fig-fill-picker-ci-okb")});return K(this.#y(U))}case"lch":{let U=this.#mj({l:J("fig-fill-picker-ci-okl")/100,c:J("fig-fill-picker-ci-okc"),h:J("fig-fill-picker-ci-okh")});return K(this.#y(U))}case"css":{let U=j("fig-fill-picker-ci-css");if(!U)return null;return this.#vj(U.value)}default:{let U=j("fig-fill-picker-ci-hex");if(!U)return null;let Q=U.value.replace(/^#/,"");if(Q.length===3)Q=Q[0]+Q[0]+Q[1]+Q[1]+Q[2]+Q[2];if(Q.length===8){let X=parseInt(Q.slice(6,8),16)/255;if(Q=Q.slice(0,6),!/^[0-9a-fA-F]{6}$/.test(Q))return null;return{...this.#E(`#${Q}`),a:X}}if(Q.length!==6||!/^[0-9a-fA-F]{6}$/.test(Q))return null;return K(this.#E(`#${Q}`))}}}#C(){if(!this.#j)return;let j=this.#V(this.#K),J=this.#n(this.#K),K=(Q)=>this.#j.querySelector(`.${Q}`),U=(Q,X)=>{let Z=K(Q);if(Z)Z.setAttribute("value",X)};switch(this.#B){case"rgb":U("fig-fill-picker-ci-r",J.r),U("fig-fill-picker-ci-g",J.g),U("fig-fill-picker-ci-b",J.b);break;case"hsl":{let Q=this.#gj(J);U("fig-fill-picker-ci-h",Math.round(Q.h)),U("fig-fill-picker-ci-s",Math.round(Q.s)),U("fig-fill-picker-ci-l",Math.round(Q.l));break}case"hsb":U("fig-fill-picker-ci-h",Math.round(this.#K.h)),U("fig-fill-picker-ci-s",Math.round(this.#K.s)),U("fig-fill-picker-ci-v",Math.round(this.#K.v));break;case"lab":{let Q=this.#Zj(J);U("fig-fill-picker-ci-okl",Math.round(Q.l*100)),U("fig-fill-picker-ci-oka",+Q.a.toFixed(3)),U("fig-fill-picker-ci-okb",+Q.b.toFixed(3));break}case"lch":{let Q=this.#hj(J);U("fig-fill-picker-ci-okl",Math.round(Q.l*100)),U("fig-fill-picker-ci-okc",+Q.c.toFixed(3)),U("fig-fill-picker-ci-okh",Math.round(Q.h));break}case"css":U("fig-fill-picker-ci-css",this.#xj(this.#K));break;default:U("fig-fill-picker-ci-hex",j.replace(/^#/,"").toUpperCase());break}if(this.#B!=="css"){let Q=Math.round(this.#K.a*1000)/10;U("fig-fill-picker-ci-a",Number.isInteger(Q)?Q:+Q.toFixed(1))}if(this.#z)this.#z.setAttribute("color",j);this.#W()}#Dj(){let j=this.#j.querySelector('[data-tab="gradient"]'),J=H(this.#J);j.innerHTML=`
70
79
  <fig-field class="fig-fill-picker-gradient-header">
71
- <fig-dropdown class="fig-fill-picker-gradient-type" label="Gradient type" ${Y} value="${this.#X.type}">
72
- <option value="linear" selected>Linear</option>
73
- <option value="radial">Radial</option>
74
- <option value="angular">Angular</option>
75
- </fig-dropdown>
76
- <fig-tooltip text="Rotate gradient">
77
- <fig-input-number class="fig-fill-picker-gradient-angle" aria-label="Gradient angle" value="${(this.#X.angle-90+360)%360}" min="0" max="360" units="°" wrap></fig-input-number>
80
+ <fig-select class="fig-fill-picker-gradient-type" label="Gradient type" value="${L(this.#J.type)}">
81
+ <fig-select-options>
82
+ <fig-select-option value="linear">Linear</fig-select-option>
83
+ <fig-select-option value="radial">Radial</fig-select-option>
84
+ <fig-select-option value="angular">Angular</fig-select-option>
85
+ </fig-select-options>
86
+ </fig-select>
87
+ <fig-tooltip text="Gradient angle">
88
+ <fig-input-number class="fig-fill-picker-gradient-angle" aria-label="Gradient angle" value="${(this.#J.angle-90+360)%360}" min="0" max="360" units="°" wrap></fig-input-number>
78
89
  </fig-tooltip>
79
90
  <div class="fig-fill-picker-gradient-center input-combo" style="display: none;">
80
- <fig-input-number min="0" max="100" aria-label="Gradient center X" value="${this.#X.centerX}" units="%" class="fig-fill-picker-gradient-cx"></fig-input-number>
81
- <fig-input-number min="0" max="100" aria-label="Gradient center Y" value="${this.#X.centerY}" units="%" class="fig-fill-picker-gradient-cy"></fig-input-number>
91
+ <fig-input-number min="0" max="100" aria-label="Gradient center X" value="${this.#J.centerX}" units="%" class="fig-fill-picker-gradient-cx"></fig-input-number>
92
+ <fig-input-number min="0" max="100" aria-label="Gradient center Y" value="${this.#J.centerY}" units="%" class="fig-fill-picker-gradient-cy"></fig-input-number>
93
+ </div>
94
+ <div class="fig-fill-picker-gradient-actions">
95
+ <fig-tooltip text="Flip gradient">
96
+ <fig-button icon variant="ghost" class="fig-fill-picker-gradient-flip" aria-label="Flip gradient">
97
+ <fig-icon name="swap"></fig-icon>
98
+ </fig-button>
99
+ </fig-tooltip>
100
+ <fig-tooltip text="Rotate gradient">
101
+ <fig-button icon variant="ghost" class="fig-fill-picker-gradient-rotate" aria-label="Rotate gradient">
102
+ <fig-icon name="rotate"></fig-icon>
103
+ </fig-button>
104
+ </fig-tooltip>
82
105
  </div>
83
- <fig-tooltip text="Flip gradient">
84
- <fig-button icon variant="ghost" class="fig-fill-picker-gradient-flip" aria-label="Flip gradient">
85
- <fig-icon name="swap"></fig-icon>
86
- </fig-button>
87
- </fig-tooltip>
88
106
  </fig-field>
89
107
  <fig-preview class="fig-fill-picker-gradient-preview">
90
- <fig-input-gradient class="fig-fill-picker-gradient-bar-input" aria-label="Gradient stops" edit="true" mode="tip" size="large" value='${JSON.stringify({type:"gradient",gradient:f(this.#X)})}'></fig-input-gradient>
108
+ <fig-input-gradient class="fig-fill-picker-gradient-bar-input" aria-label="Gradient stops" edit="true" mode="tip" size="large" value='${JSON.stringify({type:"gradient",gradient:D(this.#J)})}'></fig-input-gradient>
91
109
  </fig-preview>
92
110
  <div class="fig-fill-picker-gradient-stops">
93
111
  <fig-header class="fig-fill-picker-gradient-stops-header" borderless>
@@ -105,61 +123,60 @@ import"./fig.js";function B(Q){return String(Q??"").replace(/&/g,"&amp;").replac
105
123
  <span>Color interpolation</span>
106
124
  </fig-header>
107
125
  <fig-field class="fig-fill-picker-gradient-interpolation-field">
108
- <fig-dropdown class="fig-fill-picker-gradient-space" label="Color interpolation" full ${Y} value="${this.#X.interpolationSpace==="oklch"?`oklch-${this.#X.hueInterpolation||"shorter"}`:this.#X.interpolationSpace}">
109
- <optgroup label="sRGB">
110
- <option value="srgb">Classic</option>
111
- <option value="srgb-linear">Linear</option>
112
- </optgroup>
113
- <optgroup label="OKLab">
114
- <option value="oklab">Perceptual</option>
115
- </optgroup>
116
- <optgroup label="OKLCH">
117
- <option value="oklch-shorter">Shorter hue</option>
118
- <option value="oklch-longer">Longer hue</option>
119
- <option value="oklch-increasing">Increasing hue</option>
120
- <option value="oklch-decreasing">Decreasing hue</option>
121
- </optgroup>
122
- </fig-dropdown>
126
+ <fig-select class="fig-fill-picker-gradient-space" label="Color interpolation" full value="${L(J)}">
127
+ <fig-select-options>
128
+ ${this.#Fj()}
129
+ </fig-select-options>
130
+ </fig-select>
123
131
  </fig-field>
124
132
  </div>
125
- `,this.#G(),this.#FQ(Q)}#FQ(Q){let X=Q.querySelector(".fig-fill-picker-gradient-type"),Y=(U)=>U.currentTarget?.value??U.target?.value??U.detail,Z=(U)=>{this.#X.type=Y(U),this.#G(),this.#Z()};X.addEventListener("change",Z);let $=Q.querySelector(".fig-fill-picker-gradient-space"),j=(U)=>{let _=Y(U),M=_,R="shorter";if(_.startsWith("oklch-"))M="oklch",R=_.slice(6);this.#X=F({...this.#X,interpolationSpace:M,hueInterpolation:R}),this.#G(),this.#Z()};$?.addEventListener("change",j),Q.querySelector(".fig-fill-picker-gradient-angle").addEventListener("input",(U)=>{let _=parseFloat(U.target.value)||0;this.#X.angle=(_+90)%360,this.#R(),this.#Z()});let K=Q.querySelector(".fig-fill-picker-gradient-cx"),O=Q.querySelector(".fig-fill-picker-gradient-cy");K?.addEventListener("input",(U)=>{let _=Number.parseFloat(U.target.value);this.#X.centerX=Number.isFinite(_)?_:50,this.#R(),this.#Z()}),O?.addEventListener("input",(U)=>{let _=Number.parseFloat(U.target.value);this.#X.centerY=Number.isFinite(_)?_:50,this.#R(),this.#Z()}),Q.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#X.stops.forEach((U)=>{U.position=100-U.position}),this.#X.stops.sort((U,_)=>U.position-_.position),this.#G(),this.#Z()}),Q.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#X.stops.push({position:50,color:"#888888",opacity:100}),this.#X.stops.sort((_,M)=>_.position-M.position),this.#G(),this.#Z()});let W=Q.querySelector(".fig-fill-picker-gradient-bar-input");if(W){let U=(_)=>{if(_.stopPropagation(),this.#f)return;let M=_.detail;if(!M?.gradient)return;this.#X=F({...this.#X,...M.gradient}),this.#U(),this.#QQ()};W.addEventListener("input",(_)=>{U(_),this.#Z()}),W.addEventListener("change",(_)=>{U(_),this.#M()})}Q.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(U)=>{this.#VQ(U)})}#p(Q){let X=String(Q.color||"#888888").replace(/^#/,"").slice(0,6),Y=Q.opacity??100;if(Y>=100)return`#${X}`;let Z=Math.round(Y/100*255).toString(16).padStart(2,"0");return`#${X}${Z}`}#RQ(Q){if(!(Q instanceof HTMLElement))return"#888888";if(Q.hexOpaque)return this.#d(Q.hexOpaque);let X=Q.value;if(typeof X==="string"&&X.startsWith("#"))return this.#d(X.length>7?X.slice(0,7):X);let Y=Q.querySelector('fig-input-text:not([type="number"])'),Z=String(Y?.value??Y?.getAttribute("value")??"").replace(/#/g,"").slice(0,6);if(/^[0-9A-Fa-f]{6}$/.test(Z))return`#${Z.toUpperCase()}`;let $=Q.getAttribute("value");if(typeof $==="string"&&$.startsWith("#"))return this.#d($.length>7?$.slice(0,7):$);return"#888888"}#d(Q){let X=String(Q||"#888888").replace(/^#/,"").slice(0,6);if(!/^[0-9A-Fa-f]{6}$/.test(X))return"#888888";return`#${X.toUpperCase()}`}#BQ(Q){let X=Q.querySelector(".fig-fill-picker-stop-position"),Y=Q.querySelector(".fig-fill-picker-stop-color"),Z=parseFloat(X?.value??X?.getAttribute("value")??"0")||0,$=this.#RQ(Y),j=100;if(Y instanceof HTMLElement&&Y.rgba?.a!==void 0)j=Math.round(Y.rgba.a*100);else{let J=parseInt(Q.dataset.index,10);if(!isNaN(J)&&this.#X.stops[J])j=this.#X.stops[J].opacity??100}return{position:Z,color:$,opacity:j}}#l(Q){let X=parseInt(Q.dataset.index,10);if(isNaN(X)||X<0||X>=this.#X.stops.length)return;let Y={...this.#X.stops[X],...this.#BQ(Q)};this.#X.stops[X]=Y,this.#NQ(Q,Y)}#NQ(Q,X){let Y=Q.querySelector(".fig-fill-picker-stop-position");if(Y)Y.setAttribute("value",String(X.position));let Z=Q.querySelector(".fig-fill-picker-stop-color");if(Z)Z.setAttribute("value",this.#p(X))}#VQ(Q){let{oldIndex:X,newIndex:Y}=Q.detail??{};if(X==null||Y==null||X===Y||X<0||Y<0||X>=this.#X.stops.length||Y>=this.#X.stops.length)return;let $=Q.currentTarget.querySelectorAll(".fig-fill-picker-gradient-stop-row");$.forEach((J)=>this.#l(J));let[j]=this.#X.stops.splice(X,1);this.#X.stops.splice(Y,0,j),$.forEach((J,K)=>{J.dataset.index=String(K)}),this.#f=!0;try{this.#R(),this.#Z()}finally{this.#f=!1}}#G(){if(!this.#Q)return;let Q=this.#Q.querySelector('[data-tab="gradient"]');if(!Q)return;this.#X=F(this.#X);let X=Q.querySelector(".fig-fill-picker-gradient-angle"),Y=Q.querySelector(".fig-fill-picker-gradient-center");if(this.#X.type==="radial")X.style.display="none",Y.style.display="flex";else{X.style.display="block",Y.style.display="none";let $=(this.#X.angle-90+360)%360;X.setAttribute("value",$)}let Z=Q.querySelector(".fig-fill-picker-gradient-space");if(Z)Z.value=this.#X.interpolationSpace==="oklch"?`oklch-${this.#X.hueInterpolation||"shorter"}`:this.#X.interpolationSpace;this.#R(),this.#QQ()}#R(){if(!this.#Q)return;let Q=this.#Q.querySelector(".fig-fill-picker-gradient-bar-input");if(Q)this.#f=!0,Q.setAttribute("value",JSON.stringify({type:"gradient",gradient:f(this.#X)})),this.#f=!1;this.#U()}#QQ(){if(!this.#Q)return;let Q=this.#Q.querySelector(".fig-fill-picker-gradient-stops-list"),X=Q?.querySelector("fig-reorder");if(!Q||!X)return;let Y=X.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(Y.length===this.#X.stops.length){this.#X.stops.forEach((Z,$)=>{let j=Y[$];j.dataset.index=$;let J=j.querySelector(".fig-fill-picker-stop-position");if(J)J.setAttribute("value",Z.position);let K=j.querySelector(".fig-fill-picker-stop-color");if(K)K.setAttribute("value",this.#p(Z));let O=j.querySelector(".fig-fill-picker-stop-remove");if(O)if(this.#X.stops.length<=2)O.setAttribute("disabled","");else O.removeAttribute("disabled")});return}this.#fQ(Q)}#fQ(Q){let X=Q.querySelector("fig-reorder");if(!X)return;X.innerHTML=this.#X.stops.map((Y,Z)=>`
126
- <fig-field class="fig-fill-picker-gradient-stop-row" data-index="${Z}">
127
- <fig-input-number class="fig-fill-picker-stop-position" aria-label="Gradient stop position" min="0" max="100" value="${Y.position}" units="%"></fig-input-number>
128
- <fig-input-color class="fig-fill-picker-stop-color" aria-label="Gradient stop color" text="true" alpha="true" picker="figma" picker-dialog-position="right" value="${this.#p(Y)}"></fig-input-color>
129
- <fig-button icon variant="ghost" class="fig-fill-picker-stop-remove" ${this.#X.stops.length<=2?"disabled":""} aria-label="Remove gradient stop">
133
+ `,this.#D(),this.#Vj(j)}#Fj(){let j=["shorter","longer","increasing","decreasing"];return[{label:"Linear",options:[{value:"srgb",label:"sRGB"}]},{label:"",options:[{value:"oklab",label:"OKLAB"}]},{label:"Polar",options:j.map((K)=>({value:`oklch-${K}`,label:`OKLCH ${K.charAt(0).toUpperCase()}${K.slice(1)}`}))},{label:"",separator:!0,options:j.map((K)=>({value:`hsl-${K}`,label:`HSL ${K.charAt(0).toUpperCase()}${K.slice(1)}`}))}].map((K)=>{let U=K.options.map((X)=>{let Z=X.method?X.method.charAt(0).toUpperCase()+X.method.slice(1):"",$=X.append||Z;return`<fig-select-option value="${L(X.value)}" label="${L(X.label)}">
134
+ <fig-interpolation-swatch slot="prepend" size="large" aria-hidden="true"></fig-interpolation-swatch>
135
+ ${L(X.label)}
136
+ ${$?`<span slot="append">${L($)}</span>`:""}
137
+ </fig-select-option>`}).join("");return`${K.label||K.separator?`<fig-menu-separator${K.label?` label="${L(K.label)}"`:""}></fig-menu-separator>`:""}${U}`}).join("")}#Vj(j){let J=(Y)=>typeof Y.detail==="string"?Y.detail:Y.target?.value,K=j.querySelector(".fig-fill-picker-gradient-bar-input"),U=(Y)=>{if(!K)return;this.#L=!0;try{K.setAttribute("value",JSON.stringify({type:"gradient",gradient:D(Y)}))}finally{this.#L=!1}},Q=()=>{U(this.#J)};j.querySelector(".fig-fill-picker-gradient-type")?.addEventListener("change",(Y)=>{let W=J(Y);if(!W)return;this.#J.type=W,this.#D(),this.#Q()});let Z=j.querySelector(".fig-fill-picker-gradient-space");if(Z?.querySelectorAll("fig-select-option").forEach((Y)=>{let W=()=>{let z=q(Y.getAttribute("value")||"srgb");U(f({...this.#J,...z}))};Y.addEventListener("pointerenter",W),Y.addEventListener("pointerleave",()=>{if(document.activeElement!==Y)Q()}),Y.addEventListener("focus",W),Y.addEventListener("blur",()=>{if(!Y.matches(":hover"))Q()})}),this.#P?.disconnect(),Z)this.#P=new MutationObserver(()=>{if(!Z.hasAttribute("open"))Q()}),this.#P.observe(Z,{attributes:!0,attributeFilter:["open"]});Z?.addEventListener("change",(Y)=>{let W=J(Y);if(!W)return;let z=q(W);this.#J=f({...this.#J,...z}),this.#D(),this.#Q()}),j.querySelector(".fig-fill-picker-gradient-angle").addEventListener("input",(Y)=>{let W=parseFloat(Y.target.value)||0;this.#J.angle=(W+90)%360,this.#F(),this.#Q()});let T=j.querySelector(".fig-fill-picker-gradient-cx"),O=j.querySelector(".fig-fill-picker-gradient-cy");if(T?.addEventListener("input",(Y)=>{let W=Number.parseFloat(Y.target.value);this.#J.centerX=Number.isFinite(W)?W:50,this.#F(),this.#Q()}),O?.addEventListener("input",(Y)=>{let W=Number.parseFloat(Y.target.value);this.#J.centerY=Number.isFinite(W)?W:50,this.#F(),this.#Q()}),j.querySelector(".fig-fill-picker-gradient-rotate")?.addEventListener("click",()=>{this.#J.angle=(Number(this.#J.angle)+90)%360,this.#D(),this.#Q()}),j.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#J.stops.forEach((Y)=>{Y.position=100-Y.position}),this.#J.stops.sort((Y,W)=>Y.position-W.position),this.#D(),this.#Q()}),j.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#J.stops.push({position:50,color:"#888888",opacity:100}),this.#J.stops.sort((W,z)=>W.position-z.position),this.#D(),this.#Q()}),K){let Y=(W)=>{if(W.stopPropagation(),this.#L)return;let z=W.detail;if(!z?.gradient)return;this.#J=f({...this.#J,...z.gradient}),this.#W(),this.#w(),this.#Qj()};K.addEventListener("input",(W)=>{Y(W),this.#Q()}),K.addEventListener("change",(W)=>{Y(W),this.#k()})}j.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(Y)=>{this.#Bj(Y)})}#i(j){let J=String(j.color||"#888888").replace(/^#/,"").slice(0,6),K=j.opacity??100;if(K>=100)return`#${J}`;let U=Math.round(K/100*255).toString(16).padStart(2,"0");return`#${J}${U}`}#_j(j){if(!(j instanceof HTMLElement))return"#888888";if(j.hexOpaque)return this.#r(j.hexOpaque);let J=j.value;if(typeof J==="string"&&J.startsWith("#"))return this.#r(J.length>7?J.slice(0,7):J);let K=j.querySelector('fig-input-text:not([type="number"])'),U=String(K?.value??K?.getAttribute("value")??"").replace(/#/g,"").slice(0,6);if(/^[0-9A-Fa-f]{6}$/.test(U))return`#${U.toUpperCase()}`;let Q=j.getAttribute("value");if(typeof Q==="string"&&Q.startsWith("#"))return this.#r(Q.length>7?Q.slice(0,7):Q);return"#888888"}#r(j){let J=String(j||"#888888").replace(/^#/,"").slice(0,6);if(!/^[0-9A-Fa-f]{6}$/.test(J))return"#888888";return`#${J.toUpperCase()}`}#qj(j){let J=j.querySelector(".fig-fill-picker-stop-position"),K=j.querySelector(".fig-fill-picker-stop-color"),U=parseFloat(J?.value??J?.getAttribute("value")??"0")||0,Q=this.#_j(K),X=100;if(K instanceof HTMLElement&&K.rgba?.a!==void 0)X=Math.round(K.rgba.a*100);else{let Z=parseInt(j.dataset.index,10);if(!isNaN(Z)&&this.#J.stops[Z])X=this.#J.stops[Z].opacity??100}return{position:U,color:Q,opacity:X}}#l(j){let J=parseInt(j.dataset.index,10);if(isNaN(J)||J<0||J>=this.#J.stops.length)return;let K={...this.#J.stops[J],...this.#qj(j)};this.#J.stops[J]=K,this.#Hj(j,K)}#Hj(j,J){let K=j.querySelector(".fig-fill-picker-stop-position");if(K)K.setAttribute("value",String(J.position));let U=j.querySelector(".fig-fill-picker-stop-color");if(U)U.setAttribute("value",this.#i(J))}#Bj(j){let{oldIndex:J,newIndex:K}=j.detail??{};if(J==null||K==null||J===K||J<0||K<0||J>=this.#J.stops.length||K>=this.#J.stops.length)return;let Q=j.currentTarget.querySelectorAll(".fig-fill-picker-gradient-stop-row");Q.forEach((Z)=>this.#l(Z));let[X]=this.#J.stops.splice(J,1);this.#J.stops.splice(K,0,X),Q.forEach((Z,$)=>{Z.dataset.index=String($)}),this.#L=!0;try{this.#w(),this.#F(),this.#Q()}finally{this.#L=!1}}#D(){if(!this.#j)return;let j=this.#j.querySelector('[data-tab="gradient"]');if(!j)return;this.#J=f(this.#J);let J=j.querySelector(".fig-fill-picker-gradient-angle"),K=j.querySelector(".fig-fill-picker-gradient-rotate"),U=j.querySelector(".fig-fill-picker-gradient-center");if(this.#J.type==="radial"){if(J.style.display="none",K)K.style.display="none";U.style.display="flex"}else{J.style.removeProperty("display"),K?.style.removeProperty("display"),U.style.display="none";let X=(this.#J.angle-90+360)%360;J.setAttribute("value",X)}let Q=j.querySelector(".fig-fill-picker-gradient-space");if(Q)Q.value=H(this.#J);this.#w(),this.#F(),this.#Qj()}#Nj(){let j=Array.isArray(this.#J.stops)?[...this.#J.stops].sort((J,K)=>(J.position??0)-(K.position??0)):[];if(j.length<2)return[{color:"#FF0000",position:0},{color:"#4F9EFF",position:100}];return j.map((J)=>({color:String(J.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:J.position??0}))}#w(){if(!this.#j)return;let j=this.#Nj();this.#j.querySelectorAll("fig-interpolation-swatch").forEach((J)=>{let K=J.closest("fig-select-option")?.getAttribute("value")||"srgb",U=q(K),Q={type:"linear",stops:j,interpolationSpace:U.interpolationSpace};if(k.has(U.interpolationSpace))Q.hueInterpolation=U.hueInterpolation;J.value={type:"gradient",gradient:Q}})}#F(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-bar-input");if(j)this.#L=!0,j.setAttribute("value",JSON.stringify({type:"gradient",gradient:D(this.#J)})),this.#L=!1;this.#W()}#Qj(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-stops-list"),J=j?.querySelector("fig-reorder");if(!j||!J)return;let K=J.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(K.length===this.#J.stops.length){this.#J.stops.forEach((U,Q)=>{let X=K[Q];X.dataset.index=Q;let Z=X.querySelector(".fig-fill-picker-stop-position");if(Z)Z.setAttribute("value",U.position);let $=X.querySelector(".fig-fill-picker-stop-color");if($)$.setAttribute("value",this.#i(U));let T=X.querySelector(".fig-fill-picker-stop-remove");if(T)if(this.#J.stops.length<=2)T.setAttribute("disabled","");else T.removeAttribute("disabled")});return}this.#Cj(j)}#Cj(j){let J=j.querySelector("fig-reorder");if(!J)return;J.innerHTML=this.#J.stops.map((K,U)=>`
138
+ <fig-field class="fig-fill-picker-gradient-stop-row" data-index="${U}">
139
+ <fig-input-number class="fig-fill-picker-stop-position" aria-label="Gradient stop position" min="0" max="100" value="${K.position}" units="%"></fig-input-number>
140
+ <fig-input-color class="fig-fill-picker-stop-color" aria-label="Gradient stop color" text="true" alpha="true" picker="figma" picker-dialog-position="right" value="${this.#i(K)}"></fig-input-color>
141
+ <fig-button icon variant="ghost" class="fig-fill-picker-stop-remove" ${this.#J.stops.length<=2?"disabled":""} aria-label="Remove gradient stop">
130
142
  <fig-icon name="minus"></fig-icon>
131
143
  </fig-button>
132
144
  </fig-field>
133
- `).join(""),X.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach((Y)=>{Y.querySelector(".fig-fill-picker-stop-position").addEventListener("input",()=>{this.#l(Y),this.#R(),this.#Z()});let Z=Y.querySelector(".fig-fill-picker-stop-color"),$=Z.querySelector("fig-fill-picker");if($)$.anchorElement=this.#Q;else requestAnimationFrame(()=>{let J=Z.querySelector("fig-fill-picker");if(J)J.anchorElement=this.#Q});let j=()=>{this.#l(Y),this.#f=!0;try{this.#R(),this.#Z()}finally{this.#f=!1}};Z.addEventListener("input",j),Z.addEventListener("change",j),Y.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{let J=parseInt(Y.dataset.index,10);if(this.#X.stops.length>2)this.#X.stops.splice(J,1),this.#G(),this.#Z()})})}#i(Q,X=!0){let Y=F({...this.#X,interpolationSpace:Q??this.#X.interpolationSpace}),Z=this.#q==="display-p3",$=Y.stops.map((K)=>{let O=(K.opacity??100)/100;return`${Z?this.#AQ(K.color,O):this.#yQ(K.color,O)} ${K.position}%`}).join(", "),j=H(Y),J=X&&j?` ${j}`:"";switch(Y.type){case"linear":return`linear-gradient(${Y.angle}deg${J}, ${$})`;case"radial":return`radial-gradient(circle at ${Y.centerX}% ${Y.centerY}%${J}, ${$})`;case"angular":return`conic-gradient(from ${Y.angle}deg${J}, ${$})`;default:return`linear-gradient(${Y.angle}deg${J}, ${$})`}}static#XQ=new Map;#YQ(Q){let X=V.#XQ.get(Q);if(X!==void 0)return X;let Y=document.createElement("div");Y.style.background=Q;let Z=!!Y.style.background;return V.#XQ.set(Q,Z),Z}#ZQ(){let Q=this.#i(void 0,!0);if(this.#YQ(Q))return Q;let X=this.#i("oklab",!0);if(this.#YQ(X))return X;return this.#i("oklab",!1)}#DQ(){let Q=this.#Q.querySelector('[data-tab="image"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
145
+ `).join(""),J.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach((K)=>{K.querySelector(".fig-fill-picker-stop-position").addEventListener("input",()=>{this.#l(K),this.#w(),this.#F(),this.#Q()});let U=K.querySelector(".fig-fill-picker-stop-color"),Q=U.querySelector("fig-fill-picker");if(Q)Q.anchorElement=this.#j;else requestAnimationFrame(()=>{let Z=U.querySelector("fig-fill-picker");if(Z)Z.anchorElement=this.#j});let X=()=>{this.#l(K),this.#L=!0;try{this.#w(),this.#F(),this.#Q()}finally{this.#L=!1}};U.addEventListener("input",X),U.addEventListener("change",X),K.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{let Z=parseInt(K.dataset.index,10);if(this.#J.stops.length>2)this.#J.stops.splice(Z,1),this.#D(),this.#Q()})})}#o(j,J=!0){let K=f({...this.#J,interpolationSpace:j??this.#J.interpolationSpace}),U=this.#A==="display-p3",Q=K.stops.map(($)=>{let T=($.opacity??100)/100;return`${U?this.#uj($.color,T):this.#Ij($.color,T)} ${$.position}%`}).join(", "),X=E(K),Z=J&&X?` ${X}`:"";switch(K.type){case"linear":return`linear-gradient(${K.angle}deg${Z}, ${Q})`;case"radial":return`radial-gradient(circle at ${K.centerX}% ${K.centerY}%${Z}, ${Q})`;case"angular":return`conic-gradient(from ${K.angle}deg${Z}, ${Q})`;default:return`linear-gradient(${K.angle}deg${Z}, ${Q})`}}static#Uj=new Map;#Xj(j){let J=F.#Uj.get(j);if(J!==void 0)return J;let K=document.createElement("div");K.style.background=j;let U=!!K.style.background;return F.#Uj.set(j,U),U}#Yj(){let j=this.#o(void 0,!0);if(this.#Xj(j))return j;let J=this.#o("oklab",!0);if(this.#Xj(J))return J;return this.#o("oklab",!1)}#Mj(){let j=this.#j.querySelector('[data-tab="image"]');j.innerHTML=`
134
146
  <fig-field class="fig-fill-picker-media-header">
135
- <fig-dropdown class="fig-fill-picker-scale-mode" label="Image scale mode" ${Y} value="${this.#J.scaleMode}">
136
- <option value="fill" selected>Fill</option>
137
- <option value="fit">Fit</option>
138
- <option value="crop">Crop</option>
139
- <option value="tile">Tile</option>
140
- </fig-dropdown>
141
- <fig-input-number class="fig-fill-picker-scale" aria-label="Image tile scale" min="1" max="200" value="${this.#J.scale}" units="%" ${this.#J.scaleMode==="tile"?"":'style="display: none;"'}></fig-input-number>
147
+ <fig-select class="fig-fill-picker-scale-mode" label="Image scale mode" value="${L(this.#X.scaleMode)}">
148
+ <fig-select-options>
149
+ <fig-select-option value="fill">Fill</fig-select-option>
150
+ <fig-select-option value="fit">Fit</fig-select-option>
151
+ <fig-select-option value="crop">Crop</fig-select-option>
152
+ <fig-select-option value="tile">Tile</fig-select-option>
153
+ </fig-select-options>
154
+ </fig-select>
155
+ <fig-input-number class="fig-fill-picker-scale" aria-label="Image tile scale" min="1" max="200" value="${this.#X.scale}" units="%" ${this.#X.scaleMode==="tile"?"":'style="display: none;"'}></fig-input-number>
142
156
  <fig-button class="fig-fill-picker-media-rotate" icon variant="ghost" aria-label="Rotate">
143
157
  <fig-icon name="rotate"></fig-icon>
144
158
  </fig-button>
145
159
  </fig-field>
146
160
  <fig-image class="fig-fill-picker-media-preview fig-fill-picker-image-preview" upload="true" label="Upload from computer" alt="Image fill preview" size="auto" aspect-ratio="1/1" fit="cover" checkerboard="true"></fig-image>
147
- `,this.#GQ(Q)}#GQ(Q){let X=Q.querySelector(".fig-fill-picker-scale-mode"),Y=Q.querySelector(".fig-fill-picker-scale"),Z=Q.querySelector(".fig-fill-picker-image-preview");X.addEventListener("change",($)=>{this.#J.scaleMode=$.target.value,Y.style.display=$.target.value==="tile"?"block":"none",this.#P(Z),this.#U(),this.#Z()}),Y.addEventListener("input",($)=>{this.#J.scale=parseFloat($.target.value)||100,this.#P(Z),this.#U(),this.#Z()}),Z.addEventListener("loaded",($)=>{let j=$.detail?.src||Z.src;if(!j)return;this.#J.url=j,this.#P(Z),this.#U(),this.#Z()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#J.url=null,this.#P(Z),this.#U(),this.#Z()}),this.#P(Z)}#P(Q){if(!this.#J.url){Q.removeAttribute("src"),Q.classList.remove("has-media","is-tiled"),Q.style.backgroundImage="",Q.style.backgroundPosition="",Q.style.backgroundRepeat="",Q.style.backgroundSize="";return}Q.setAttribute("src",this.#J.url),Q.classList.add("has-media"),Q.style.backgroundImage="",Q.style.backgroundPosition="",Q.style.backgroundRepeat="",Q.style.backgroundSize="",Q.mediaEl?.style.removeProperty("opacity");let X=Q.querySelector("fig-input-file[data-generated]");if(X)X.setAttribute("label","Replace"),X.removeAttribute("url");switch(this.#J.scaleMode){case"fill":Q.classList.remove("is-tiled"),Q.setAttribute("fit","cover");break;case"crop":Q.classList.remove("is-tiled"),Q.setAttribute("fit","cover");break;case"fit":Q.classList.remove("is-tiled"),Q.setAttribute("fit","contain");break;case"tile":if(Q.classList.add("is-tiled"),Q.setAttribute("fit","none"),Q.style.backgroundImage=`url(${this.#J.url})`,Q.style.backgroundPosition="top left",Q.style.backgroundSize=`${this.#J.scale}%`,Q.style.backgroundRepeat="repeat",Q.mediaEl)Q.mediaEl.style.opacity="0";break}}#u(Q){if(Q.tagName==="FIG-MEDIA"){if(!this.#K.url){Q.removeAttribute("src"),Q.classList.remove("has-media");return}Q.setAttribute("src",this.#K.url),Q.classList.add("has-media");let X=Q.querySelector("fig-input-file[data-generated]");if(X)X.setAttribute("label","Replace"),X.removeAttribute("url");switch(this.#K.scaleMode){case"fill":case"crop":Q.setAttribute("fit","cover");break;case"fit":Q.setAttribute("fit","contain");break}return}switch(Q.style.objectPosition="center",Q.style.width="100%",Q.style.height="100%",this.#K.scaleMode){case"fill":case"crop":Q.style.objectFit="cover";break;case"fit":Q.style.objectFit="contain";break}}#HQ(){let Q=this.#Q.querySelector('[data-tab="video"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
161
+ `,this.#yj(j)}#yj(j){let J=j.querySelector(".fig-fill-picker-scale-mode"),K=j.querySelector(".fig-fill-picker-scale"),U=j.querySelector(".fig-fill-picker-image-preview");J.addEventListener("change",(Q)=>{let X=typeof Q.detail==="string"?Q.detail:Q.target?.value;if(!X)return;this.#X.scaleMode=X,K.style.display=X==="tile"?"block":"none",this.#M(U),this.#W(),this.#Q()}),K.addEventListener("input",(Q)=>{this.#X.scale=parseFloat(Q.target.value)||100,this.#M(U),this.#W(),this.#Q()}),U.addEventListener("loaded",(Q)=>{let X=Q.detail?.src||U.src;if(!X)return;this.#X.url=X,this.#M(U),this.#W(),this.#Q()}),U.addEventListener("change",()=>{if(U.src)return;this.#X.url=null,this.#M(U),this.#W(),this.#Q()}),this.#M(U)}#M(j){if(!this.#X.url){j.removeAttribute("src"),j.classList.remove("has-media","is-tiled"),j.style.backgroundImage="",j.style.backgroundPosition="",j.style.backgroundRepeat="",j.style.backgroundSize="";return}j.setAttribute("src",this.#X.url),j.classList.add("has-media"),j.style.backgroundImage="",j.style.backgroundPosition="",j.style.backgroundRepeat="",j.style.backgroundSize="",j.mediaEl?.style.removeProperty("opacity");let J=j.querySelector("fig-input-file[data-generated]");if(J)J.setAttribute("label","Replace"),J.removeAttribute("url");switch(this.#X.scaleMode){case"fill":j.classList.remove("is-tiled"),j.setAttribute("fit","cover");break;case"crop":j.classList.remove("is-tiled"),j.setAttribute("fit","cover");break;case"fit":j.classList.remove("is-tiled"),j.setAttribute("fit","contain");break;case"tile":if(j.classList.add("is-tiled"),j.setAttribute("fit","none"),j.style.backgroundImage=`url(${this.#X.url})`,j.style.backgroundPosition="top left",j.style.backgroundSize=`${this.#X.scale}%`,j.style.backgroundRepeat="repeat",j.mediaEl)j.mediaEl.style.opacity="0";break}}#d(j){if(j.tagName==="FIG-MEDIA"){if(!this.#Z.url){j.removeAttribute("src"),j.classList.remove("has-media");return}j.setAttribute("src",this.#Z.url),j.classList.add("has-media");let J=j.querySelector("fig-input-file[data-generated]");if(J)J.setAttribute("label","Replace"),J.removeAttribute("url");switch(this.#Z.scaleMode){case"fill":case"crop":j.setAttribute("fit","cover");break;case"fit":j.setAttribute("fit","contain");break}return}switch(j.style.objectPosition="center",j.style.width="100%",j.style.height="100%",this.#Z.scaleMode){case"fill":case"crop":j.style.objectFit="cover";break;case"fit":j.style.objectFit="contain";break}}#Ej(){let j=this.#j.querySelector('[data-tab="video"]');j.innerHTML=`
148
162
  <fig-field class="fig-fill-picker-media-header">
149
- <fig-dropdown class="fig-fill-picker-scale-mode" label="Video scale mode" ${Y} value="${this.#K.scaleMode}">
150
- <option value="fill" selected>Fill</option>
151
- <option value="fit">Fit</option>
152
- <option value="crop">Crop</option>
153
- </fig-dropdown>
163
+ <fig-select class="fig-fill-picker-scale-mode" label="Video scale mode" value="${L(this.#Z.scaleMode)}">
164
+ <fig-select-options>
165
+ <fig-select-option value="fill">Fill</fig-select-option>
166
+ <fig-select-option value="fit">Fit</fig-select-option>
167
+ <fig-select-option value="crop">Crop</fig-select-option>
168
+ </fig-select-options>
169
+ </fig-select>
154
170
  <fig-button class="fig-fill-picker-media-rotate" icon variant="ghost" aria-label="Rotate">
155
171
  <fig-icon name="rotate"></fig-icon>
156
172
  </fig-button>
157
173
  </fig-field>
158
174
  <fig-media class="fig-fill-picker-media-preview fig-fill-picker-video-preview" type="video" upload="true" label="Upload from computer" aria-label="Video fill preview" size="auto" aspect-ratio="1/1" fit="cover" checkerboard="true" autoplay="true" controls muted="true" loop="true"></fig-media>
159
- `,this.#EQ(Q)}#EQ(Q){let X=Q.querySelector(".fig-fill-picker-scale-mode"),Y=Q.querySelector(".fig-fill-picker-video-preview");X.addEventListener("change",(Z)=>{this.#K.scaleMode=Z.target.value,this.#u(Y),this.#U(),this.#Z()}),Y.addEventListener("loaded",(Z)=>{let $=Z.detail?.src||Y.src;if(!$)return;this.#K.url=$,this.#u(Y),Y.play?.(),this.#U(),this.#Z()}),Y.addEventListener("change",()=>{if(Y.src)return;this.#K.url=null,this.#u(Y),this.#U(),this.#Z()}),this.#u(Y)}#PQ(){let Q=this.#Q.querySelector('[data-tab="webcam"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
175
+ `,this.#Aj(j)}#Aj(j){let J=j.querySelector(".fig-fill-picker-scale-mode"),K=j.querySelector(".fig-fill-picker-video-preview");J.addEventListener("change",(U)=>{let Q=typeof U.detail==="string"?U.detail:U.target?.value;if(!Q)return;this.#Z.scaleMode=Q,this.#d(K),this.#W(),this.#Q()}),K.addEventListener("loaded",(U)=>{let Q=U.detail?.src||K.src;if(!Q)return;this.#Z.url=Q,this.#d(K),K.play?.(),this.#W(),this.#Q()}),K.addEventListener("change",()=>{if(K.src)return;this.#Z.url=null,this.#d(K),this.#W(),this.#Q()}),this.#d(K)}#Pj(){let j=this.#j.querySelector('[data-tab="webcam"]');j.innerHTML=`
160
176
  <fig-field class="fig-fill-picker-webcam-camera" style="display: none;">
161
- <fig-dropdown class="fig-fill-picker-camera-select" label="Camera" full ${Y}>
162
- </fig-dropdown>
177
+ <fig-select class="fig-fill-picker-camera-select" label="Camera" full>
178
+ <fig-select-options></fig-select-options>
179
+ </fig-select>
163
180
  </fig-field>
164
181
  <fig-video class="fig-fill-picker-webcam-preview" aria-label="Webcam preview" aspect-ratio="1/1" fit="cover" checkerboard="true" autoplay="true" muted="true">
165
182
  <video class="fig-fill-picker-webcam-video" autoplay muted playsinline></video>
@@ -172,4 +189,4 @@ import"./fig.js";function B(Q){return String(Q??"").replace(/&/g,"&amp;").replac
172
189
  Capture
173
190
  </fig-button>
174
191
  </div>
175
- `,this.#TQ(Q)}#TQ(Q){let X=Q.querySelector(".fig-fill-picker-webcam-video"),Y=Q.querySelector(".fig-fill-picker-webcam-status"),Z=Q.querySelector(".fig-fill-picker-webcam-capture"),$=Q.querySelector(".fig-fill-picker-webcam-camera"),j=Q.querySelector(".fig-fill-picker-camera-select"),J=async(K=null)=>{this.#b();let O=this.#A;try{let W={video:K?{deviceId:{exact:K}}:!0},L=await navigator.mediaDevices.getUserMedia(W);if(O!==this.#A||!this.isConnected||this.#S!=="webcam"){L.getTracks().forEach((M)=>M.stop());return}this.#W.stream=L,X.srcObject=L,X.style.display="block",Y.style.display="none";let U=await navigator.mediaDevices.enumerateDevices();if(O!==this.#A)return;let _=U.filter((M)=>M.kind==="videoinput");if(_.length>1){if($.style.display="",j.querySelectorAll(":scope > option, :scope > optgroup").forEach((M)=>M.remove()),_.forEach((M,R)=>{let q=document.createElement("option");q.value=M.deviceId;let z=M.label||(_.length>1?`Camera ${R+1}`:"Camera");q.textContent=z.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(k,N)=>{return` ${/^\d+$/.test(N)?Number.parseInt(N,10).toString():N.replace(/^0+/,"")||"0"}`}),j.append(q)}),K)j.value=K}else $.style.display="none",j.querySelectorAll(":scope > option, :scope > optgroup").forEach((M)=>M.remove())}catch(W){if(O!==this.#A)return;console.error("Webcam error:",W.name,W.message);let L="Camera access denied";if(W.name==="NotAllowedError")L="Camera permission denied";else if(W.name==="NotFoundError")L="No camera found";else if(W.name==="NotReadableError")L="Camera in use by another app";else if(W.name==="OverconstrainedError")L="Camera constraints not supported";else if(!window.isSecureContext)L="Camera requires secure context";Y.replaceChildren();let U=document.createElement("span");U.textContent=L,Y.appendChild(U),Y.style.display="flex",X.style.display="none"}};this.#s=J,j.addEventListener("change",(K)=>{J(K.target.value)}),Z.addEventListener("click",async()=>{if(!this.#W.stream)return;if(!X.videoWidth||!X.videoHeight)return;let K=document.createElement("canvas");K.width=X.videoWidth,K.height=X.videoHeight,K.getContext("2d").drawImage(X,0,0,K.width,K.height);let O=await new Promise((L)=>K.toBlob(L,"image/png"));if(!O)return;if(this.#W.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#W.snapshot);this.#W.snapshot=URL.createObjectURL(O),this.#J.url=this.#W.snapshot;let W=this.#Q.querySelector(".fig-fill-picker-image-preview");if(W)this.#P(W);this.#c("image")})}#$Q(Q){let X=Q.h/360,Y=Q.s/100,Z=Q.v/100,$,j,J,K=Math.floor(X*6),O=X*6-K,W=Z*(1-Y),L=Z*(1-O*Y),U=Z*(1-(1-O)*Y);switch(K%6){case 0:$=Z,j=U,J=W;break;case 1:$=L,j=Z,J=W;break;case 2:$=W,j=Z,J=U;break;case 3:$=W,j=L,J=Z;break;case 4:$=U,j=W,J=Z;break;case 5:$=Z,j=W,J=L;break}return{r:Math.round($*255),g:Math.round(j*255),b:Math.round(J*255)}}#C(Q){let X=Q.r/255,Y=Q.g/255,Z=Q.b/255,$=Math.max(X,Y,Z),j=Math.min(X,Y,Z),J=$-j,K=0,O=$===0?0:J/$,W=$;if($!==j){switch($){case X:K=(Y-Z)/J+(Y<Z?6:0);break;case Y:K=(Z-X)/J+2;break;case Z:K=(X-Y)/J+4;break}K/=6}return{h:K*360,s:O*100,v:W*100,a:1}}#B(Q){if(!Q||typeof Q.h!=="number"||typeof Q.s!=="number"||typeof Q.v!=="number")return"#D9D9D9";let X=this.#$Q(Q),Y=(Z)=>{return(isNaN(Z)?217:Math.max(0,Math.min(255,Math.round(Z)))).toString(16).padStart(2,"0")};return`#${Y(X.r)}${Y(X.g)}${Y(X.b)}`}#m(Q){let X=parseInt(Q.slice(1,3),16),Y=parseInt(Q.slice(3,5),16),Z=parseInt(Q.slice(5,7),16);return this.#C({r:X,g:Y,b:Z})}#yQ(Q,X=1){let Y=parseInt(Q.slice(1,3),16),Z=parseInt(Q.slice(3,5),16),$=parseInt(Q.slice(5,7),16);return`rgba(${Y}, ${Z}, ${$}, ${X})`}#AQ(Q,X=1){let Y=+(parseInt(Q.slice(1,3),16)/255).toFixed(4),Z=+(parseInt(Q.slice(3,5),16)/255).toFixed(4),$=+(parseInt(Q.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${Y} ${Z} ${$} / ${X})`}#CQ(Q){let X=Q.r/255,Y=Q.g/255,Z=Q.b/255,$=Math.max(X,Y,Z),j=Math.min(X,Y,Z),J,K,O=($+j)/2;if($===j)J=K=0;else{let W=$-j;switch(K=O>0.5?W/(2-$-j):W/($+j),$){case X:J=((Y-Z)/W+(Y<Z?6:0))/6;break;case Y:J=((Z-X)/W+2)/6;break;case Z:J=((X-Y)/W+4)/6;break}}return{h:J*360,s:K*100,l:O*100}}#SQ(Q){let X=Q.h/360,Y=Q.s/100,Z=Q.l/100,$,j,J;if(Y===0)$=j=J=Z;else{let K=(L,U,_)=>{if(_<0)_+=1;if(_>1)_-=1;if(_<0.16666666666666666)return L+(U-L)*6*_;if(_<0.5)return U;if(_<0.6666666666666666)return L+(U-L)*(0.6666666666666666-_)*6;return L},O=Z<0.5?Z*(1+Y):Z+Y-Z*Y,W=2*Z-O;$=K(W,O,X+0.3333333333333333),j=K(W,O,X),J=K(W,O,X-0.3333333333333333)}return{r:Math.round($*255),g:Math.round(j*255),b:Math.round(J*255)}}#JQ(Q){let X=(U)=>{return U=U/255,U<=0.04045?U/12.92:Math.pow((U+0.055)/1.055,2.4)},Y=X(Q.r),Z=X(Q.g),$=X(Q.b),j=0.4122214708*Y+0.5363325363*Z+0.0514459929*$,J=0.2119034982*Y+0.6806995451*Z+0.1073969566*$,K=0.0883024619*Y+0.2817188376*Z+0.6299787005*$,O=Math.cbrt(j),W=Math.cbrt(J),L=Math.cbrt(K);return{l:0.2104542553*O+0.793617785*W-0.0040720468*L,a:1.9779984951*O-2.428592205*W+0.4505937099*L,b:0.0259040371*O+0.7827717662*W-0.808675766*L}}#xQ(Q){let X=this.#JQ(Q);return{l:X.l,c:Math.sqrt(X.a*X.a+X.b*X.b),h:(Math.atan2(X.b,X.a)*180/Math.PI+360)%360}}#jQ(Q){let X=Q.l+0.3963377774*Q.a+0.2158037573*Q.b,Y=Q.l-0.1055613458*Q.a-0.0638541728*Q.b,Z=Q.l-0.0894841775*Q.a-1.291485548*Q.b,$=X*X*X,j=Y*Y*Y,J=Z*Z*Z,K=(O)=>{let W=O<=0.0031308?12.92*O:1.055*Math.pow(O,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,W))*255)};return{r:K(4.0767416621*$-3.3077115913*j+0.2309699292*J),g:K(-1.2684380046*$+2.6097574011*j-0.3413193965*J),b:K(-0.0041960863*$-0.7034186147*j+1.707614701*J)}}#IQ(Q){let X=Q.h*Math.PI/180;return this.#jQ({l:Q.l,a:Q.c*Math.cos(X),b:Q.c*Math.sin(X)})}#Z(){this.#U(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#M(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let Q={type:this.#O,colorSpace:this.#q};switch(this.#O){case"solid":return{...Q,color:this.#B(this.#Y),alpha:this.#Y.a,hsv:{...this.#Y}};case"gradient":return{...Q,gradient:f(this.#X),css:this.#ZQ()};case"image":return{...Q,image:{...this.#J}};case"video":return{...Q,video:{...this.#K}};case"webcam":return{...Q,image:{url:this.#W.snapshot,scaleMode:"fill",scale:50}};default:return{...Q,...this.#x[this.#O]}}}set value(Q){if(typeof Q==="string")this.setAttribute("value",Q);else this.setAttribute("value",JSON.stringify(Q))}attributeChangedCallback(Q,X,Y){if(X===Y)return;switch(Q){case"value":if(this.#r(),this.#U(),this.#Q){if(!this.#V){if(this.#z(),this.#E(),this.#N)this.#N.setAttribute("value",this.#Y.h);if(this.#F)this.#F.setAttribute("value",this.#Y.a*100),this.#F.setAttribute("color",this.#B(this.#Y))}}break;case"disabled":this.#w();break;case"alpha":case"mode":case"experimental":{if(!this.#Q)break;let Z=this.#Q.open;if(this.#a(),Z&&this.isConnected)this.#h();break}case"aria-label":case"aria-labelledby":case"aria-describedby":this.#w();break}}}customElements.define("fig-fill-picker",V);
192
+ `,this.#Sj(j)}#Sj(j){let J=j.querySelector(".fig-fill-picker-webcam-video"),K=j.querySelector(".fig-fill-picker-webcam-status"),U=j.querySelector(".fig-fill-picker-webcam-capture"),Q=j.querySelector(".fig-fill-picker-webcam-camera"),X=j.querySelector(".fig-fill-picker-camera-select"),Z=async($=null)=>{this.#m();let T=this.#I;try{let O={video:$?{deviceId:{exact:$}}:!0},R=await navigator.mediaDevices.getUserMedia(O);if(T!==this.#I||!this.isConnected||this.#x!=="webcam"){R.getTracks().forEach((z)=>z.stop());return}this.#$.stream=R,J.srcObject=R,J.style.display="block",K.style.display="none";let Y=await navigator.mediaDevices.enumerateDevices();if(T!==this.#I)return;let W=Y.filter((z)=>z.kind==="videoinput");if(W.length>1){Q.style.display="";let z=X.querySelector(":scope > fig-select-options");if(!z)z=document.createElement("fig-select-options"),X.append(z);if(z.replaceChildren(),W.forEach((G,B)=>{let V=document.createElement("fig-select-option");V.value=G.deviceId;let N=G.label||(W.length>1?`Camera ${B+1}`:"Camera");V.textContent=N.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(A,_)=>{return` ${/^\d+$/.test(_)?Number.parseInt(_,10).toString():_.replace(/^0+/,"")||"0"}`}),z.append(V)}),$)X.value=$}else Q.style.display="none",X.querySelector(":scope > fig-select-options")?.replaceChildren()}catch(O){if(T!==this.#I)return;console.error("Webcam error:",O.name,O.message);let R="Camera access denied";if(O.name==="NotAllowedError")R="Camera permission denied";else if(O.name==="NotFoundError")R="No camera found";else if(O.name==="NotReadableError")R="Camera in use by another app";else if(O.name==="OverconstrainedError")R="Camera constraints not supported";else if(!window.isSecureContext)R="Camera requires secure context";K.replaceChildren();let Y=document.createElement("span");Y.textContent=R,K.appendChild(Y),K.style.display="flex",J.style.display="none"}};this.#c=Z,X.addEventListener("change",($)=>{let T=typeof $.detail==="string"?$.detail:$.target?.value;if(T)Z(T)}),U.addEventListener("click",async()=>{if(!this.#$.stream)return;if(!J.videoWidth||!J.videoHeight)return;let $=document.createElement("canvas");$.width=J.videoWidth,$.height=J.videoHeight,$.getContext("2d").drawImage(J,0,0,$.width,$.height);let T=await new Promise((R)=>$.toBlob(R,"image/png"));if(!T)return;if(this.#$.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#$.snapshot);this.#$.snapshot=URL.createObjectURL(T),this.#X.url=this.#$.snapshot;let O=this.#j.querySelector(".fig-fill-picker-image-preview");if(O)this.#M(O);this.#s("image")})}#n(j){let J=j.h/360,K=j.s/100,U=j.v/100,Q,X,Z,$=Math.floor(J*6),T=J*6-$,O=U*(1-K),R=U*(1-T*K),Y=U*(1-(1-T)*K);switch($%6){case 0:Q=U,X=Y,Z=O;break;case 1:Q=R,X=U,Z=O;break;case 2:Q=O,X=U,Z=Y;break;case 3:Q=O,X=R,Z=U;break;case 4:Q=Y,X=O,Z=U;break;case 5:Q=U,X=O,Z=R;break}return{r:Math.round(Q*255),g:Math.round(X*255),b:Math.round(Z*255)}}#y(j){let J=j.r/255,K=j.g/255,U=j.b/255,Q=Math.max(J,K,U),X=Math.min(J,K,U),Z=Q-X,$=0,T=Q===0?0:Z/Q,O=Q;if(Q!==X){switch(Q){case J:$=(K-U)/Z+(K<U?6:0);break;case K:$=(U-J)/Z+2;break;case U:$=(J-K)/Z+4;break}$/=6}return{h:$*360,s:T*100,v:O*100,a:1}}#V(j){if(!j||typeof j.h!=="number"||typeof j.s!=="number"||typeof j.v!=="number")return"#D9D9D9";let J=this.#n(j),K=(U)=>{return(isNaN(U)?217:Math.max(0,Math.min(255,Math.round(U)))).toString(16).padStart(2,"0")};return`#${K(J.r)}${K(J.g)}${K(J.b)}`}#E(j){let J=parseInt(j.slice(1,3),16),K=parseInt(j.slice(3,5),16),U=parseInt(j.slice(5,7),16);return this.#y({r:J,g:K,b:U})}#Ij(j,J=1){let K=parseInt(j.slice(1,3),16),U=parseInt(j.slice(3,5),16),Q=parseInt(j.slice(5,7),16);return`rgba(${K}, ${U}, ${Q}, ${J})`}#wj(j){let J=Math.max(0,Math.min(1,Number(j)||0)),K=Math.round(J*1000)/1000;return String(K)}#xj(j=this.#K){let J=this.#n(j);return`rgba(${J.r}, ${J.g}, ${J.b}, ${this.#wj(j.a)})`}#vj(j){let J=String(j??"").trim();if(!J)return null;let K=J.match(/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(K){let Q=K[1];if(Q.length===3)Q=Q[0]+Q[0]+Q[1]+Q[1]+Q[2]+Q[2];let X=1;if(Q.length===8)X=parseInt(Q.slice(6,8),16)/255,Q=Q.slice(0,6);return{...this.#E(`#${Q}`),a:X}}let U=J.match(/^rgba?\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))(?:\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*)?\)$/i);if(U){let Q=Math.max(0,Math.min(255,Math.round(parseFloat(U[1])))),X=Math.max(0,Math.min(255,Math.round(parseFloat(U[2])))),Z=Math.max(0,Math.min(255,Math.round(parseFloat(U[3])))),$=U[4]!==void 0?Math.max(0,Math.min(1,parseFloat(U[4]))):1;if(![Q,X,Z,$].every(Number.isFinite))return null;return{...this.#y({r:Q,g:X,b:Z}),a:$}}return null}#uj(j,J=1){let K=+(parseInt(j.slice(1,3),16)/255).toFixed(4),U=+(parseInt(j.slice(3,5),16)/255).toFixed(4),Q=+(parseInt(j.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${K} ${U} ${Q} / ${J})`}#gj(j){let J=j.r/255,K=j.g/255,U=j.b/255,Q=Math.max(J,K,U),X=Math.min(J,K,U),Z,$,T=(Q+X)/2;if(Q===X)Z=$=0;else{let O=Q-X;switch($=T>0.5?O/(2-Q-X):O/(Q+X),Q){case J:Z=((K-U)/O+(K<U?6:0))/6;break;case K:Z=((U-J)/O+2)/6;break;case U:Z=((J-K)/O+4)/6;break}}return{h:Z*360,s:$*100,l:T*100}}#bj(j){let J=j.h/360,K=j.s/100,U=j.l/100,Q,X,Z;if(K===0)Q=X=Z=U;else{let $=(R,Y,W)=>{if(W<0)W+=1;if(W>1)W-=1;if(W<0.16666666666666666)return R+(Y-R)*6*W;if(W<0.5)return Y;if(W<0.6666666666666666)return R+(Y-R)*(0.6666666666666666-W)*6;return R},T=U<0.5?U*(1+K):U+K-U*K,O=2*U-T;Q=$(O,T,J+0.3333333333333333),X=$(O,T,J),Z=$(O,T,J-0.3333333333333333)}return{r:Math.round(Q*255),g:Math.round(X*255),b:Math.round(Z*255)}}#Zj(j){let J=(Y)=>{return Y=Y/255,Y<=0.04045?Y/12.92:Math.pow((Y+0.055)/1.055,2.4)},K=J(j.r),U=J(j.g),Q=J(j.b),X=0.4122214708*K+0.5363325363*U+0.0514459929*Q,Z=0.2119034982*K+0.6806995451*U+0.1073969566*Q,$=0.0883024619*K+0.2817188376*U+0.6299787005*Q,T=Math.cbrt(X),O=Math.cbrt(Z),R=Math.cbrt($);return{l:0.2104542553*T+0.793617785*O-0.0040720468*R,a:1.9779984951*T-2.428592205*O+0.4505937099*R,b:0.0259040371*T+0.7827717662*O-0.808675766*R}}#hj(j){let J=this.#Zj(j);return{l:J.l,c:Math.sqrt(J.a*J.a+J.b*J.b),h:(Math.atan2(J.b,J.a)*180/Math.PI+360)%360}}#$j(j){let J=j.l+0.3963377774*j.a+0.2158037573*j.b,K=j.l-0.1055613458*j.a-0.0638541728*j.b,U=j.l-0.0894841775*j.a-1.291485548*j.b,Q=J*J*J,X=K*K*K,Z=U*U*U,$=(T)=>{let O=T<=0.0031308?12.92*T:1.055*Math.pow(T,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,O))*255)};return{r:$(4.0767416621*Q-3.3077115913*X+0.2309699292*Z),g:$(-1.2684380046*Q+2.6097574011*X-0.3413193965*Z),b:$(-0.0041960863*Q-0.7034186147*X+1.707614701*Z)}}#mj(j){let J=j.h*Math.PI/180;return this.#$j({l:j.l,a:j.c*Math.cos(J),b:j.c*Math.sin(J)})}#Q(){this.#W(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#k(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let j={type:this.#O,colorSpace:this.#A};switch(this.#O){case"solid":return{...j,color:this.#V(this.#K),alpha:this.#K.a,hsv:{...this.#K}};case"gradient":return{...j,gradient:D(this.#J),css:this.#Yj()};case"image":return{...j,image:{...this.#X}};case"video":return{...j,video:{...this.#Z}};case"webcam":return{...j,image:{url:this.#$.snapshot,scaleMode:"fill",scale:50}};default:return{...j,...this.#v[this.#O]}}}set value(j){if(typeof j==="string")this.setAttribute("value",j);else this.setAttribute("value",JSON.stringify(j))}attributeChangedCallback(j,J,K){if(J===K)return;switch(j){case"value":if(this.#t(),this.#W(),this.#j){if(!this.#q){if(this.#f(),this.#C(),this.#_)this.#_.setAttribute("value",this.#K.h);if(this.#z)this.#z.setAttribute("value",this.#K.a*100),this.#z.setAttribute("color",this.#V(this.#K))}}break;case"disabled":this.#b();break;case"alpha":case"mode":case"experimental":{if(!this.#j)break;let U=this.#j.open;if(this.#jj(),U&&this.isConnected)this.#h();break}case"aria-label":case"aria-labelledby":case"aria-describedby":this.#b();break}}}C("fig-fill-picker",F);