@rogieking/figui3 5.1.0 → 5.1.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,14 +1,14 @@
1
- import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradientConfig as k}from"./fig.js";class N extends HTMLElement{#y=null;#$=null;#Q=null;#b="solid";anchorElement=null;#U="solid";#L="srgb";#Y={h:0,s:0,v:85,a:1};#H="hex";#X={type:"linear",angle:0,centerX:50,centerY:50,interpolationSpace:"oklab",hueInterpolation:"shorter",stops:[{position:0,color:"#D9D9D9",opacity:100},{position:100,color:"#737373",opacity:100}]};#j={url:null,scaleMode:"fill",scale:50};#J={url:null,scaleMode:"fill",scale:50};#K={stream:null,snapshot:null};#R={};#A={};#z=null;#O=null;#N=null;#B=null;#M=!1;#F=null;#T=null;#P=null;constructor(){super()}static get observedAttributes(){return["value","disabled","alpha","mode","experimental"]}connectedCallback(){this.style.display="contents",requestAnimationFrame(()=>{this.#o(),this.#h(),this.#W()})}disconnectedCallback(){if(this.#F)this.#F(),this.#F=null;if(this.#T)this.#T.disconnect(),this.#T=null;if(this.#P)this.#P.disconnect(),this.#P=null;if(this.#K.stream)this.#K.stream.getTracks().forEach((Q)=>Q.stop()),this.#K.stream=null;if(this.#K.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#K.snapshot),this.#K.snapshot=null;if(this.#J.url&&this.#J.url.startsWith("blob:"))URL.revokeObjectURL(this.#J.url);if(this.#$)this.#$.removeAttribute("selected");if(this.#Q)this.#Q.close(),this.#Q.remove(),this.#Q=null}#o(){let Q=Array.from(this.children).find((X)=>!X.getAttribute("slot")?.startsWith("mode-"));if(!Q)this.#$=document.createElement("fig-chit"),this.#$.setAttribute("background","#D9D9D9"),this.appendChild(this.#$),this.#y=this.#$;else if(Q.tagName==="FIG-CHIT")this.#$=Q,this.#y=Q;else this.#y=Q,this.#$=null;if(this.#y.addEventListener("click",(X)=>{if(this.hasAttribute("disabled"))return;X.stopPropagation(),X.preventDefault(),this.#m()}),this.#$)requestAnimationFrame(()=>{let X=this.#$.querySelector('input[type="color"]');if(X)X.style.pointerEvents="none"})}#h(){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.#U=Y.type;if(Y.color){if(typeof Y.color==="string")this.#Y=this.#C(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.#L=Y.colorSpace;if(Y.gradient)this.#X=k({...this.#X,...Y.gradient});if(Y.image)this.#j={...this.#j,...Y.image};if(Y.video)this.#J={...this.#J,...Y.video};if(Y.type&&!X.includes(Y.type)){let{type:Z,...$}=Y;this.#A[Y.type]=$}}catch(Y){if(Q.startsWith("#"))this.#U="solid",this.#Y=this.#C(Q)}}#W(){if(!this.#$)return;let Q,X="cover",Y="center";switch(this.#U){case"solid":Q=this.#k(this.#Y);break;case"gradient":Q=this.#i();break;case"image":if(this.#j.url){Q=`url(${this.#j.url})`;let $=this.#u(this.#j.scaleMode,this.#j.scale);X=$.size,Y=$.position}else Q="";break;case"video":if(this.#J.url){Q=`url(${this.#J.url})`;let $=this.#u(this.#J.scaleMode,this.#J.scale);X=$.size,Y=$.position}else Q="";break;default:Q=this.#R[this.#U]?.element?.getAttribute("chit-background")||"#D9D9D9"}if(this.#$.setAttribute("background",Q),this.#$.style.setProperty("--chit-bg-size",X),this.#$.style.setProperty("--chit-bg-position",Y),this.#U==="solid")this.#$.setAttribute("alpha",this.#Y.a);else this.#$.removeAttribute("alpha")}#u(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"}}}#m(){if(!this.#Q)this.#t();this.#x(this.#U);let Q=this.#Q.querySelector(".fig-fill-picker-gamut");if(Q)Q.value=this.#L;if(this.#$)this.#$.setAttribute("selected","true");this.#Q.open=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#G(),this.#q()})})}open(){this.#m()}close(){if(this.#Q)this.#Q.open=!1}#t(){this.#R={},this.querySelectorAll('[slot^="mode-"]').forEach((q)=>{let R=q.getAttribute("slot").slice(5);this.#R[R]={element:q,label:q.getAttribute("label")||R.charAt(0).toUpperCase()+R.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.#y;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((R)=>R.trim().toLowerCase()).filter((R)=>X.includes(R)||this.#R[R]),$.length===0)$=[...X]}else $=[...X];let j={...Y};for(let[q,{label:R}]of Object.entries(this.#R))j[q]=R;if(!$.includes(this.#U))this.#U=$[0],this.#b=$[0];let J=this.getAttribute("experimental"),U=J?`experimental="${J}"`:"",L;if($.length===1)L=`<h3 class="fig-fill-picker-type-label">${j[$[0]]}</h3>`;else{let q=$.map((R)=>`<option value="${R}">${j[R]}</option>`).join(`
1
+ var N=["srgb","srgb-linear","display-p3","oklab","oklch"],f=["shorter","longer","increasing","decreasing"];function O(j){let Q={...j??{}},X=String(Q.interpolationSpace??"oklab").toLowerCase();if(!N.includes(X))X="oklab";if(X==="srgb"||X==="display-p3")X="oklab";Q.interpolationSpace=X;let Y=String(Q.hueInterpolation??"shorter").toLowerCase();return Q.hueInterpolation=f.includes(Y)?Y:"shorter",Q}function V(j){let Q=O(j),X={...Q,interpolationSpace:Q.interpolationSpace};if(Q.interpolationSpace==="oklch")X.hueInterpolation=Q.hueInterpolation;else delete X.hueInterpolation;return X}function D(j){let Q=O(j);if(Q.interpolationSpace==="oklch")return`in oklch ${Q.hueInterpolation} hue`;return`in ${Q.interpolationSpace}`}class M extends HTMLElement{#E=null;#Z=null;#j=null;#b="solid";anchorElement=null;#U="solid";#L="srgb";#X={h:0,s:0,v:85,a:1};#H="hex";#Q={type:"linear",angle:0,centerX:50,centerY:50,interpolationSpace:"oklab",hueInterpolation:"shorter",stops:[{position:0,color:"#D9D9D9",opacity:100},{position:100,color:"#737373",opacity:100}]};#$={url:null,scaleMode:"fill",scale:50};#J={url:null,scaleMode:"fill",scale:50};#K={stream:null,snapshot:null};#R={};#S={};#q=null;#B=null;#M=null;#k=null;#F=!1;#V=null;#T=null;#P=null;constructor(){super()}static get observedAttributes(){return["value","disabled","alpha","mode","experimental"]}connectedCallback(){this.style.display="contents",requestAnimationFrame(()=>{this.#o(),this.#h(),this.#W()})}disconnectedCallback(){if(this.#V)this.#V(),this.#V=null;if(this.#T)this.#T.disconnect(),this.#T=null;if(this.#P)this.#P.disconnect(),this.#P=null;if(this.#K.stream)this.#K.stream.getTracks().forEach((j)=>j.stop()),this.#K.stream=null;if(this.#K.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#K.snapshot),this.#K.snapshot=null;if(this.#J.url&&this.#J.url.startsWith("blob:"))URL.revokeObjectURL(this.#J.url);if(this.#Z)this.#Z.removeAttribute("selected");if(this.#j)this.#j.close(),this.#j.remove(),this.#j=null}#o(){let j=Array.from(this.children).find((Q)=>!Q.getAttribute("slot")?.startsWith("mode-"));if(!j)this.#Z=document.createElement("fig-chit"),this.#Z.setAttribute("background","#D9D9D9"),this.appendChild(this.#Z),this.#E=this.#Z;else if(j.tagName==="FIG-CHIT")this.#Z=j,this.#E=j;else this.#E=j,this.#Z=null;if(this.#E.addEventListener("click",(Q)=>{if(this.hasAttribute("disabled"))return;Q.stopPropagation(),Q.preventDefault(),this.#m()}),this.#Z)requestAnimationFrame(()=>{let Q=this.#Z.querySelector('input[type="color"]');if(Q)Q.style.pointerEvents="none"})}#h(){let j=this.getAttribute("value");if(!j)return;let Q=["solid","gradient","image","video","webcam"];try{let X=JSON.parse(j);if(X.type)this.#U=X.type;if(X.color){if(typeof X.color==="string")this.#X=this.#I(X.color);else if(typeof X.color==="object"&&X.color.h!==void 0)this.#X=X.color}if(X.opacity!==void 0)this.#X.a=X.opacity/100;if(X.colorSpace==="display-p3"||X.colorSpace==="srgb")this.#L=X.colorSpace;if(X.gradient)this.#Q=O({...this.#Q,...X.gradient});if(X.image)this.#$={...this.#$,...X.image};if(X.video)this.#J={...this.#J,...X.video};if(X.type&&!Q.includes(X.type)){let{type:Y,...Z}=X;this.#S[X.type]=Z}}catch(X){if(j.startsWith("#"))this.#U="solid",this.#X=this.#I(j)}}#W(){if(!this.#Z)return;let j,Q="cover",X="center";switch(this.#U){case"solid":j=this.#O(this.#X);break;case"gradient":j=this.#l();break;case"image":if(this.#$.url){j=`url(${this.#$.url})`;let Z=this.#u(this.#$.scaleMode,this.#$.scale);Q=Z.size,X=Z.position}else j="";break;case"video":if(this.#J.url){j=`url(${this.#J.url})`;let Z=this.#u(this.#J.scaleMode,this.#J.scale);Q=Z.size,X=Z.position}else j="";break;default:j=this.#R[this.#U]?.element?.getAttribute("chit-background")||"#D9D9D9"}if(this.#Z.setAttribute("background",j),this.#Z.style.setProperty("--chit-bg-size",Q),this.#Z.style.setProperty("--chit-bg-position",X),this.#U==="solid")this.#Z.setAttribute("alpha",this.#X.a);else this.#Z.removeAttribute("alpha")}#u(j,Q){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:`${Q}%`,position:"top left"};default:return{size:"cover",position:"center"}}}#m(){if(!this.#j)this.#t();this.#x(this.#U);let j=this.#j.querySelector(".fig-fill-picker-gamut");if(j)j.value=this.#L;if(this.#Z)this.#Z.setAttribute("selected","true");this.#j.open=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#D(),this.#_()})})}open(){this.#m()}close(){if(this.#j)this.#j.open=!1}#t(){this.#R={},this.querySelectorAll('[slot^="mode-"]').forEach((_)=>{let R=_.getAttribute("slot").slice(5);this.#R[R]={element:_,label:_.getAttribute("label")||R.charAt(0).toUpperCase()+R.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.#E;let j=this.getAttribute("dialog-position")||"left";this.#j.setAttribute("position",j),this.#j.setAttribute("offset",this.getAttribute("dialog-offset")||"8 8");let Q=["solid","gradient","image","video","webcam"],X={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},Y=this.getAttribute("mode"),Z;if(Y){if(Z=Y.split(",").map((R)=>R.trim().toLowerCase()).filter((R)=>Q.includes(R)||this.#R[R]),Z.length===0)Z=[...Q]}else Z=[...Q];let $={...X};for(let[_,{label:R}]of Object.entries(this.#R))$[_]=R;if(!Z.includes(this.#U))this.#U=Z[0],this.#b=Z[0];let J=this.getAttribute("experimental"),U=J?`experimental="${J}"`:"",L;if(Z.length===1)L=`<h3 class="fig-fill-picker-type-label">${$[Z[0]]}</h3>`;else{let _=Z.map((R)=>`<option value="${R}">${$[R]}</option>`).join(`
2
2
  `);L=`<fig-dropdown class="fig-fill-picker-type" ${U} value="${this.#U}">
3
- ${q}
4
- </fig-dropdown>`}let K=$.map((q)=>`<div class="fig-fill-picker-tab" data-tab="${q}"></div>`).join(`
5
- `),z=`<fig-dropdown class="fig-fill-picker-gamut" ${U} value="${this.#L}">
3
+ ${_}
4
+ </fig-dropdown>`}let K=Z.map((_)=>`<div class="fig-fill-picker-tab" data-tab="${_}"></div>`).join(`
5
+ `),q=`<fig-dropdown class="fig-fill-picker-gamut" ${U} value="${this.#L}">
6
6
  <option value="srgb">sRGB</option>
7
7
  <option value="display-p3">Display P3</option>
8
- </fig-dropdown>`;this.#Q.innerHTML=`
8
+ </fig-dropdown>`;this.#j.innerHTML=`
9
9
  <fig-header>
10
10
  ${L}
11
- ${z}
11
+ ${q}
12
12
  <fig-button icon variant="ghost" class="fig-fill-picker-close">
13
13
  <fig-icon name="close"></fig-icon>
14
14
  </fig-button>
@@ -16,12 +16,12 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
16
16
  <fig-content>
17
17
  ${K}
18
18
  </fig-content>
19
- `,document.body.appendChild(this.#Q);for(let[q,{element:R}]of Object.entries(this.#R)){let O=this.#Q.querySelector(`[data-tab="${q}"]`);if(!O)continue;while(R.firstChild)O.appendChild(R.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:q,container:O}}))}let W=this.#Q.querySelector(".fig-fill-picker-type");if(W)W.addEventListener("change",(q)=>{this.#x(q.target.value)});let _=this.#Q.querySelector(".fig-fill-picker-gamut");if(_){let q=(R)=>{let O=R.currentTarget?.value??R.target?.value??R.detail;if(O&&O!==this.#L)this.#L=O,this.#e()};_.addEventListener("input",q),_.addEventListener("change",q)}this.#Q.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#Q.open=!1});let B=()=>{if(this.#$)this.#$.removeAttribute("selected");this.#_(),this.dispatchEvent(new CustomEvent("close"))};this.#Q.addEventListener("close",B),this.#T=new MutationObserver(()=>{if(!(this.#Q.hasAttribute("open")&&this.#Q.getAttribute("open")!=="false"))B()}),this.#T.observe(this.#Q,{attributes:!0,attributeFilter:["open"]});let M={solid:()=>this.#a(),gradient:()=>this.#YQ(),image:()=>this.#jQ(),video:()=>this.#KQ(),webcam:()=>this.#UQ()};for(let[q,R]of Object.entries(M))if(!this.#R[q]&&$.includes(q))R();for(let q of Object.keys(this.#R)){if(X.includes(q))continue;let R=this.#Q.querySelector(`[data-tab="${q}"]`);if(!R)continue;R.addEventListener("input",(O)=>{if(O.target===this)return;if(O.stopPropagation(),O.detail)this.#A[q]=O.detail;this.#Z()}),R.addEventListener("change",(O)=>{if(O.target===this)return;if(O.stopPropagation(),O.detail)this.#A[q]=O.detail;this.#_()})}}#x(Q){let X=this.#Q?.querySelector(`.fig-fill-picker-tab[data-tab="${Q}"]`);if(!X)return;this.#b=Q,this.#U=Q;let Y=this.#Q.querySelector(".fig-fill-picker-type");if(Y&&Y.value!==Q)Y.value=Q;this.#Q.querySelectorAll(".fig-fill-picker-tab").forEach((j)=>{if(j.dataset.tab===Q)j.style.display="block";else j.style.display="none"});let $=this.#Q.querySelector("fig-content");if($)$.style.padding=this.#R[Q]?"0":"";if(Q==="gradient")requestAnimationFrame(()=>{this.#V();let j=X.querySelector(".fig-fill-picker-gradient-bar-input");j?.refreshLayout?.(),requestAnimationFrame(()=>{j?.refreshLayout?.()})});this.#W(),this.#Z()}#a(){let Q=this.#Q.querySelector('[data-tab="solid"]'),X=this.getAttribute("alpha")!=="false",Y=this.getAttribute("experimental"),Z=Y?`experimental="${Y}"`:"";if(Q.innerHTML=`
19
+ `,document.body.appendChild(this.#j);for(let[_,{element:R}]of Object.entries(this.#R)){let B=this.#j.querySelector(`[data-tab="${_}"]`);if(!B)continue;while(R.firstChild)B.appendChild(R.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:_,container:B}}))}let W=this.#j.querySelector(".fig-fill-picker-type");if(W)W.addEventListener("change",(_)=>{this.#x(_.target.value)});let z=this.#j.querySelector(".fig-fill-picker-gamut");if(z){let _=(R)=>{let B=R.currentTarget?.value??R.target?.value??R.detail;if(B&&B!==this.#L)this.#L=B,this.#e()};z.addEventListener("input",_),z.addEventListener("change",_)}this.#j.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#j.open=!1});let k=()=>{if(this.#Z)this.#Z.removeAttribute("selected");this.#z(),this.dispatchEvent(new CustomEvent("close"))};this.#j.addEventListener("close",k),this.#T=new MutationObserver(()=>{if(!(this.#j.hasAttribute("open")&&this.#j.getAttribute("open")!=="false"))k()}),this.#T.observe(this.#j,{attributes:!0,attributeFilter:["open"]});let F={solid:()=>this.#a(),gradient:()=>this.#Xj(),image:()=>this.#$j(),video:()=>this.#Kj(),webcam:()=>this.#Uj()};for(let[_,R]of Object.entries(F))if(!this.#R[_]&&Z.includes(_))R();for(let _ of Object.keys(this.#R)){if(Q.includes(_))continue;let R=this.#j.querySelector(`[data-tab="${_}"]`);if(!R)continue;R.addEventListener("input",(B)=>{if(B.target===this)return;if(B.stopPropagation(),B.detail)this.#S[_]=B.detail;this.#Y()}),R.addEventListener("change",(B)=>{if(B.target===this)return;if(B.stopPropagation(),B.detail)this.#S[_]=B.detail;this.#z()})}}#x(j){let Q=this.#j?.querySelector(`.fig-fill-picker-tab[data-tab="${j}"]`);if(!Q)return;this.#b=j,this.#U=j;let X=this.#j.querySelector(".fig-fill-picker-type");if(X&&X.value!==j)X.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.#N();let $=Q.querySelector(".fig-fill-picker-gradient-bar-input");$?.refreshLayout?.(),requestAnimationFrame(()=>{$?.refreshLayout?.()})});this.#W(),this.#Y()}#a(){let j=this.#j.querySelector('[data-tab="solid"]'),Q=this.getAttribute("alpha")!=="false",X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";if(j.innerHTML=`
20
20
  <fig-preview class="fig-fill-picker-color-area">
21
21
  <canvas width="200" height="200"></canvas>
22
22
  <fig-handle
23
23
  type="color"
24
- color="${this.#k({...this.#Y,a:1})}"
24
+ color="${this.#O({...this.#X,a:1})}"
25
25
  data-no-color-picker
26
26
  drag
27
27
  drag-surface=".fig-fill-picker-color-area"
@@ -31,11 +31,11 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
31
31
  </fig-preview>
32
32
  <div class="fig-fill-picker-sliders">
33
33
  <fig-tooltip text="Sample color"><fig-button icon variant="ghost" class="fig-fill-picker-eyedropper"><fig-icon name="eyedropper"></fig-icon></fig-button></fig-tooltip>
34
- <fig-slider type="hue" text="false" min="0" max="360" value="${this.#Y.h}"></fig-slider>
35
- ${X?`<fig-slider type="opacity" text="true" units="%" min="0" max="100" value="${this.#Y.a*100}" color="${this.#k(this.#Y)}"></fig-slider>`:""}
34
+ <fig-slider type="hue" text="false" min="0" max="360" value="${this.#X.h}"></fig-slider>
35
+ ${Q?`<fig-slider type="opacity" text="true" units="%" min="0" max="100" value="${this.#X.a*100}" color="${this.#O(this.#X)}"></fig-slider>`:""}
36
36
  </div>
37
37
  <fig-field class="fig-fill-picker-inputs">
38
- <fig-dropdown class="fig-fill-picker-input-mode" ${Z} value="${this.#H}">
38
+ <fig-dropdown class="fig-fill-picker-input-mode" ${Y} value="${this.#H}">
39
39
  <option value="hex">Hex</option>
40
40
  <option value="rgb">RGB</option>
41
41
  <option value="hsl">HSL</option>
@@ -45,39 +45,39 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
45
45
  </fig-dropdown>
46
46
  <span class="fig-fill-picker-input-fields"></span>
47
47
  </fig-field>
48
- `,this.#z=Q.querySelector("canvas"),this.#O=Q.querySelector("fig-handle"),this.#G(),this.#q(),this.#g(),this.#N=Q.querySelector('fig-slider[type="hue"]'),this.#N.addEventListener("input",(J)=>{this.#Y.h=parseFloat(J.target.value),this.#G(),this.#q(),this.#D(),this.#Z()}),this.#N.addEventListener("change",()=>{this.#_()}),X)this.#B=Q.querySelector('fig-slider[type="opacity"]'),this.#B.addEventListener("input",(J)=>{this.#Y.a=parseFloat(J.target.value)/100,this.#D(),this.#Z()}),this.#B.addEventListener("change",()=>{this.#_()});Q.querySelector(".fig-fill-picker-input-mode").addEventListener("input",(J)=>{this.#H=J.target.value,this.#s()}),this.#s();let j=Q.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)j.addEventListener("click",async()=>{try{let U=await new EyeDropper().open();this.#Y={...this.#C(U.sRGBHex),a:this.#Y.a},this.#G(),this.#q(),this.#D(),this.#Z()}catch(J){}});else j.setAttribute("disabled",""),j.title="EyeDropper not supported in this browser"}#e(){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.#z=Y,this.#g()}this.#G(),this.#q()}this.#f(),this.#Z()}#G(){if(!this.#z&&this.#Q)this.#z=this.#Q.querySelector('[data-tab="solid"] canvas');if(!this.#z)return;let Q=this.#L==="display-p3"?"display-p3":"srgb",X=this.#z.getContext("2d",{colorSpace:Q});if(!X)return;let Y=this.#z.width,Z=this.#z.height;X.clearRect(0,0,Y,Z);let $=this.#Y.h,j=this.#L==="display-p3",J=X.createLinearGradient(0,0,Y,0);if(j){J.addColorStop(0,"color(display-p3 1 1 1)");let[L,K,z]=hslToP3($,100,50);J.addColorStop(1,`color(display-p3 ${L} ${K} ${z})`)}else J.addColorStop(0,"#FFFFFF"),J.addColorStop(1,`hsl(${$}, 100%, 50%)`);X.fillStyle=J,X.fillRect(0,0,Y,Z);let U=X.createLinearGradient(0,0,0,Z);U.addColorStop(0,"rgba(0,0,0,0)"),U.addColorStop(1,"rgba(0,0,0,1)"),X.fillStyle=U,X.fillRect(0,0,Y,Z)}#q(Q=0){if(!this.#O||!this.#z)return;let X=this.#z.getBoundingClientRect();if((X.width===0||X.height===0)&&Q<5){requestAnimationFrame(()=>this.#q(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.#O.setAttribute("value",`${Y}% ${Z}%`),this.#O.setAttribute("color",this.#k({...this.#Y,a:1}))}#w(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.#O)this.#O.setAttribute("color",this.#k({...this.#Y,a:1}));if(Z)this.#q();if(this.#D(),$)this.#Z();if(j)this.#_()}#g(){if(this.#F)this.#F(),this.#F=null;if(!this.#z||!this.#O)return;let Q=this.#z.parentElement||this.#z,X=this.#O,Y=!1,Z=(K,z={})=>{let W=Q.getBoundingClientRect();if(W.width===0||W.height===0)return;let _=Math.max(0,Math.min(K.clientX-W.left,W.width)),B=Math.max(0,Math.min(K.clientY-W.top,W.height));this.#w(_/W.width,B/W.height,z)},$=(K)=>{if(K.button!==0)return;if(K.target===X||X.contains(K.target))return;Y=!0,this.#M=!0,Q.setPointerCapture(K.pointerId),Z(K,{updateHandle:!0,emitInput:!0})},j=(K)=>{if(!Y)return;if(K.buttons===0){J();return}Z(K,{updateHandle:!0,emitInput:!0})},J=()=>{if(!Y)return;Y=!1,this.#M=!1,this.#_()},U=(K)=>{this.#M=!0;let z=K.detail?.px,W=K.detail?.py;if(!Number.isFinite(z)||!Number.isFinite(W))return;X.setAttribute("value",`${z*100}% ${W*100}%`),this.#w(z,W,{updateHandle:!1,emitInput:!0})},L=(K)=>{let z=K.detail?.px,W=K.detail?.py;if(Number.isFinite(z)&&Number.isFinite(W))X.setAttribute("value",`${z*100}% ${W*100}%`),this.#w(z,W,{updateHandle:!1,emitInput:!1});this.#M=!1,this.#_()};Q.addEventListener("pointerdown",$),Q.addEventListener("pointermove",j),Q.addEventListener("pointerup",J),Q.addEventListener("pointercancel",J),Q.addEventListener("lostpointercapture",J),X.addEventListener("input",U),X.addEventListener("change",L),this.#F=()=>{Q.removeEventListener("pointerdown",$),Q.removeEventListener("pointermove",j),Q.removeEventListener("pointerup",J),Q.removeEventListener("pointercancel",J),Q.removeEventListener("lostpointercapture",J),X.removeEventListener("input",U),X.removeEventListener("change",L),this.#M=!1}}#s(){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,U)=>`<fig-input-number class="${$}" min="${j}" max="${J}"${U!=null?` step="${U}"`:""}></fig-input-number>`,Z;switch(this.#H){case"rgb":Z=`<div class="input-combo">
49
- ${X("Red",Y("fig-fill-picker-ci-r",0,255))}
50
- ${X("Green",Y("fig-fill-picker-ci-g",0,255))}
51
- ${X("Blue",Y("fig-fill-picker-ci-b",0,255))}
52
- </div>`;break;case"hsl":Z=`<div class="input-combo">
53
- ${X("Hue",Y("fig-fill-picker-ci-h",0,360))}
54
- ${X("Saturation",Y("fig-fill-picker-ci-s",0,100))}
55
- ${X("Lightness",Y("fig-fill-picker-ci-l",0,100))}
56
- </div>`;break;case"hsb":Z=`<div class="input-combo">
57
- ${X("Hue",Y("fig-fill-picker-ci-h",0,360))}
58
- ${X("Saturation",Y("fig-fill-picker-ci-s",0,100))}
59
- ${X("Brightness",Y("fig-fill-picker-ci-v",0,100))}
60
- </div>`;break;case"lab":Z=`<div class="input-combo">
61
- ${X("Lightness",Y("fig-fill-picker-ci-okl",0,100))}
62
- ${X("Green-Red axis",Y("fig-fill-picker-ci-oka",-0.4,0.4,0.001))}
63
- ${X("Blue-Yellow axis",Y("fig-fill-picker-ci-okb",-0.4,0.4,0.001))}
64
- </div>`;break;case"lch":Z=`<div class="input-combo">
65
- ${X("Lightness",Y("fig-fill-picker-ci-okl",0,100))}
66
- ${X("Chroma",Y("fig-fill-picker-ci-okc",0,0.4,0.001))}
67
- ${X("Hue",Y("fig-fill-picker-ci-okh",0,360))}
68
- </div>`;break;default:Z='<fig-input-text class="fig-fill-picker-ci-hex" placeholder="FFFFFF"></fig-input-text>';break}Q.innerHTML=Z,this.#QQ(),requestAnimationFrame(()=>this.#D())}#QQ(){let Q=this.#Q?.querySelector(".fig-fill-picker-input-fields");if(!Q)return;let X=()=>{if(this.#M)return;let $=this.#XQ();if(!$)return;if(this.#Y={...$,a:this.#Y.a},this.#G(),this.#q(),this.#N)this.#N.setAttribute("value",this.#Y.h);this.#Z()},Y=()=>this.#_();Q.querySelectorAll("fig-input-number, fig-input-text").forEach(($)=>{$.addEventListener("input",X),$.addEventListener("change",Y)})}#XQ(){let Q=(Y)=>this.#Q?.querySelector(`.${Y}`),X=(Y)=>parseFloat(Q(Y)?.value??0);switch(this.#H){case"rgb":return this.#S({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.#_Q({h:X("fig-fill-picker-ci-h"),s:X("fig-fill-picker-ci-s"),l:X("fig-fill-picker-ci-l")});return this.#S(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.#r({l:X("fig-fill-picker-ci-okl")/100,a:X("fig-fill-picker-ci-oka"),b:X("fig-fill-picker-ci-okb")});return this.#S(Y)}case"lch":{let Y=this.#BQ({l:X("fig-fill-picker-ci-okl")/100,c:X("fig-fill-picker-ci-okc"),h:X("fig-fill-picker-ci-okh")});return this.#S(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.#C(`#${Z}`)}}}#D(){if(!this.#Q)return;let Q=this.#k(this.#Y),X=this.#l(this.#Y),Y=($)=>this.#Q.querySelector(`.${$}`),Z=($,j)=>{let J=Y($);if(J)J.setAttribute("value",j)};switch(this.#H){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.#qQ(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.#n(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.#OQ(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.#B)this.#B.setAttribute("color",Q);this.#W()}#YQ(){let Q=this.#Q.querySelector('[data-tab="gradient"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
48
+ `,this.#q=j.querySelector("canvas"),this.#B=j.querySelector("fig-handle"),this.#D(),this.#_(),this.#s(),this.#M=j.querySelector('fig-slider[type="hue"]'),this.#M.addEventListener("input",(J)=>{this.#X.h=parseFloat(J.target.value),this.#D(),this.#_(),this.#G(),this.#Y()}),this.#M.addEventListener("change",()=>{this.#z()}),Q)this.#k=j.querySelector('fig-slider[type="opacity"]'),this.#k.addEventListener("input",(J)=>{this.#X.a=parseFloat(J.target.value)/100,this.#G(),this.#Y()}),this.#k.addEventListener("change",()=>{this.#z()});j.querySelector(".fig-fill-picker-input-mode").addEventListener("input",(J)=>{this.#H=J.target.value,this.#g()}),this.#g();let $=j.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)$.addEventListener("click",async()=>{try{let U=await new EyeDropper().open();this.#X={...this.#I(U.sRGBHex),a:this.#X.a},this.#D(),this.#_(),this.#G(),this.#Y()}catch(J){}});else $.setAttribute("disabled",""),$.title="EyeDropper not supported in this browser"}#e(){let j=this.#j?.querySelector('[data-tab="solid"]');if(j){let Q=j.querySelector("canvas");if(Q){let X=document.createElement("canvas");X.width=Q.width,X.height=Q.height,Q.replaceWith(X),this.#q=X,this.#s()}this.#D(),this.#_()}this.#f(),this.#Y()}#D(){if(!this.#q&&this.#j)this.#q=this.#j.querySelector('[data-tab="solid"] canvas');if(!this.#q)return;let j=this.#L==="display-p3"?"display-p3":"srgb",Q=this.#q.getContext("2d",{colorSpace:j});if(!Q)return;let X=this.#q.width,Y=this.#q.height;Q.clearRect(0,0,X,Y);let Z=this.#X.h,$=this.#L==="display-p3",J=Q.createLinearGradient(0,0,X,0);if($){J.addColorStop(0,"color(display-p3 1 1 1)");let[L,K,q]=hslToP3(Z,100,50);J.addColorStop(1,`color(display-p3 ${L} ${K} ${q})`)}else J.addColorStop(0,"#FFFFFF"),J.addColorStop(1,`hsl(${Z}, 100%, 50%)`);Q.fillStyle=J,Q.fillRect(0,0,X,Y);let U=Q.createLinearGradient(0,0,0,Y);U.addColorStop(0,"rgba(0,0,0,0)"),U.addColorStop(1,"rgba(0,0,0,1)"),Q.fillStyle=U,Q.fillRect(0,0,X,Y)}#_(j=0){if(!this.#B||!this.#q)return;let Q=this.#q.getBoundingClientRect();if((Q.width===0||Q.height===0)&&j<5){requestAnimationFrame(()=>this.#_(j+1));return}let X=Math.max(0,Math.min(100,this.#X.s)),Y=Math.max(0,Math.min(100,100-this.#X.v));this.#B.setAttribute("value",`${X}% ${Y}%`),this.#B.setAttribute("color",this.#O({...this.#X,a:1}))}#w(j,Q,X={}){let{updateHandle:Y=!0,emitInput:Z=!0,emitChange:$=!1}=X;if(this.#X.s=Math.max(0,Math.min(100,j*100)),this.#X.v=Math.max(0,Math.min(100,(1-Q)*100)),this.#B)this.#B.setAttribute("color",this.#O({...this.#X,a:1}));if(Y)this.#_();if(this.#G(),Z)this.#Y();if($)this.#z()}#s(){if(this.#V)this.#V(),this.#V=null;if(!this.#q||!this.#B)return;let j=this.#q.parentElement||this.#q,Q=this.#B,X=!1,Y=(K,q={})=>{let W=j.getBoundingClientRect();if(W.width===0||W.height===0)return;let z=Math.max(0,Math.min(K.clientX-W.left,W.width)),k=Math.max(0,Math.min(K.clientY-W.top,W.height));this.#w(z/W.width,k/W.height,q)},Z=(K)=>{if(K.button!==0)return;if(K.target===Q||Q.contains(K.target))return;X=!0,this.#F=!0,j.setPointerCapture(K.pointerId),Y(K,{updateHandle:!0,emitInput:!0})},$=(K)=>{if(!X)return;if(K.buttons===0){J();return}Y(K,{updateHandle:!0,emitInput:!0})},J=()=>{if(!X)return;X=!1,this.#F=!1,this.#z()},U=(K)=>{this.#F=!0;let q=K.detail?.px,W=K.detail?.py;if(!Number.isFinite(q)||!Number.isFinite(W))return;Q.setAttribute("value",`${q*100}% ${W*100}%`),this.#w(q,W,{updateHandle:!1,emitInput:!0})},L=(K)=>{let q=K.detail?.px,W=K.detail?.py;if(Number.isFinite(q)&&Number.isFinite(W))Q.setAttribute("value",`${q*100}% ${W*100}%`),this.#w(q,W,{updateHandle:!1,emitInput:!1});this.#F=!1,this.#z()};j.addEventListener("pointerdown",Z),j.addEventListener("pointermove",$),j.addEventListener("pointerup",J),j.addEventListener("pointercancel",J),j.addEventListener("lostpointercapture",J),Q.addEventListener("input",U),Q.addEventListener("change",L),this.#V=()=>{j.removeEventListener("pointerdown",Z),j.removeEventListener("pointermove",$),j.removeEventListener("pointerup",J),j.removeEventListener("pointercancel",J),j.removeEventListener("lostpointercapture",J),Q.removeEventListener("input",U),Q.removeEventListener("change",L),this.#F=!1}}#g(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let Q=(Z,$)=>`<fig-tooltip text="${Z}">${$}</fig-tooltip>`,X=(Z,$,J,U)=>`<fig-input-number class="${Z}" min="${$}" max="${J}"${U!=null?` step="${U}"`:""}></fig-input-number>`,Y;switch(this.#H){case"rgb":Y=`<div class="input-combo">
49
+ ${Q("Red",X("fig-fill-picker-ci-r",0,255))}
50
+ ${Q("Green",X("fig-fill-picker-ci-g",0,255))}
51
+ ${Q("Blue",X("fig-fill-picker-ci-b",0,255))}
52
+ </div>`;break;case"hsl":Y=`<div class="input-combo">
53
+ ${Q("Hue",X("fig-fill-picker-ci-h",0,360))}
54
+ ${Q("Saturation",X("fig-fill-picker-ci-s",0,100))}
55
+ ${Q("Lightness",X("fig-fill-picker-ci-l",0,100))}
56
+ </div>`;break;case"hsb":Y=`<div class="input-combo">
57
+ ${Q("Hue",X("fig-fill-picker-ci-h",0,360))}
58
+ ${Q("Saturation",X("fig-fill-picker-ci-s",0,100))}
59
+ ${Q("Brightness",X("fig-fill-picker-ci-v",0,100))}
60
+ </div>`;break;case"lab":Y=`<div class="input-combo">
61
+ ${Q("Lightness",X("fig-fill-picker-ci-okl",0,100))}
62
+ ${Q("Green-Red axis",X("fig-fill-picker-ci-oka",-0.4,0.4,0.001))}
63
+ ${Q("Blue-Yellow axis",X("fig-fill-picker-ci-okb",-0.4,0.4,0.001))}
64
+ </div>`;break;case"lch":Y=`<div class="input-combo">
65
+ ${Q("Lightness",X("fig-fill-picker-ci-okl",0,100))}
66
+ ${Q("Chroma",X("fig-fill-picker-ci-okc",0,0.4,0.001))}
67
+ ${Q("Hue",X("fig-fill-picker-ci-okh",0,360))}
68
+ </div>`;break;default:Y='<fig-input-text class="fig-fill-picker-ci-hex" placeholder="FFFFFF"></fig-input-text>';break}j.innerHTML=Y,this.#jj(),requestAnimationFrame(()=>this.#G())}#jj(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let Q=()=>{if(this.#F)return;let Z=this.#Qj();if(!Z)return;if(this.#X={...Z,a:this.#X.a},this.#D(),this.#_(),this.#M)this.#M.setAttribute("value",this.#X.h);this.#Y()},X=()=>this.#z();j.querySelectorAll("fig-input-number, fig-input-text").forEach((Z)=>{Z.addEventListener("input",Q),Z.addEventListener("change",X)})}#Qj(){let j=(X)=>this.#j?.querySelector(`.${X}`),Q=(X)=>parseFloat(j(X)?.value??0);switch(this.#H){case"rgb":return this.#A({r:Q("fig-fill-picker-ci-r"),g:Q("fig-fill-picker-ci-g"),b:Q("fig-fill-picker-ci-b")});case"hsl":{let X=this.#zj({h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),l:Q("fig-fill-picker-ci-l")});return this.#A(X)}case"hsb":return{h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),v:Q("fig-fill-picker-ci-v"),a:1};case"lab":{let X=this.#n({l:Q("fig-fill-picker-ci-okl")/100,a:Q("fig-fill-picker-ci-oka"),b:Q("fig-fill-picker-ci-okb")});return this.#A(X)}case"lch":{let X=this.#kj({l:Q("fig-fill-picker-ci-okl")/100,c:Q("fig-fill-picker-ci-okc"),h:Q("fig-fill-picker-ci-okh")});return this.#A(X)}default:{let X=j("fig-fill-picker-ci-hex");if(!X)return null;let Y=X.value.replace(/^#/,"");if(Y.length===3)Y=Y[0]+Y[0]+Y[1]+Y[1]+Y[2]+Y[2];if(Y.length!==6||!/^[0-9a-fA-F]{6}$/.test(Y))return null;return this.#I(`#${Y}`)}}}#G(){if(!this.#j)return;let j=this.#O(this.#X),Q=this.#i(this.#X),X=(Z)=>this.#j.querySelector(`.${Z}`),Y=(Z,$)=>{let J=X(Z);if(J)J.setAttribute("value",$)};switch(this.#H){case"rgb":Y("fig-fill-picker-ci-r",Q.r),Y("fig-fill-picker-ci-g",Q.g),Y("fig-fill-picker-ci-b",Q.b);break;case"hsl":{let Z=this.#_j(Q);Y("fig-fill-picker-ci-h",Math.round(Z.h)),Y("fig-fill-picker-ci-s",Math.round(Z.s)),Y("fig-fill-picker-ci-l",Math.round(Z.l));break}case"hsb":Y("fig-fill-picker-ci-h",Math.round(this.#X.h)),Y("fig-fill-picker-ci-s",Math.round(this.#X.s)),Y("fig-fill-picker-ci-v",Math.round(this.#X.v));break;case"lab":{let Z=this.#r(Q);Y("fig-fill-picker-ci-okl",Math.round(Z.l*100)),Y("fig-fill-picker-ci-oka",+Z.a.toFixed(3)),Y("fig-fill-picker-ci-okb",+Z.b.toFixed(3));break}case"lch":{let Z=this.#Bj(Q);Y("fig-fill-picker-ci-okl",Math.round(Z.l*100)),Y("fig-fill-picker-ci-okc",+Z.c.toFixed(3)),Y("fig-fill-picker-ci-okh",Math.round(Z.h));break}default:Y("fig-fill-picker-ci-hex",j.replace(/^#/,"").toUpperCase());break}if(this.#k)this.#k.setAttribute("color",j);this.#W()}#Xj(){let j=this.#j.querySelector('[data-tab="gradient"]'),Q=this.getAttribute("experimental"),X=Q?`experimental="${Q}"`:"";j.innerHTML=`
69
69
  <fig-field class="fig-fill-picker-gradient-header">
70
- <fig-dropdown class="fig-fill-picker-gradient-type" ${Y} value="${this.#X.type}">
70
+ <fig-dropdown class="fig-fill-picker-gradient-type" ${X} value="${this.#Q.type}">
71
71
  <option value="linear" selected>Linear</option>
72
72
  <option value="radial">Radial</option>
73
73
  <option value="angular">Angular</option>
74
74
  </fig-dropdown>
75
75
  <fig-tooltip text="Rotate gradient">
76
- <fig-input-number class="fig-fill-picker-gradient-angle" value="${(this.#X.angle-90+360)%360}" min="0" max="360" units="°" wrap></fig-input-number>
76
+ <fig-input-number class="fig-fill-picker-gradient-angle" value="${(this.#Q.angle-90+360)%360}" min="0" max="360" units="°" wrap></fig-input-number>
77
77
  </fig-tooltip>
78
78
  <div class="fig-fill-picker-gradient-center input-combo" style="display: none;">
79
- <fig-input-number min="0" max="100" value="${this.#X.centerX}" units="%" class="fig-fill-picker-gradient-cx"></fig-input-number>
80
- <fig-input-number min="0" max="100" value="${this.#X.centerY}" units="%" class="fig-fill-picker-gradient-cy"></fig-input-number>
79
+ <fig-input-number min="0" max="100" value="${this.#Q.centerX}" units="%" class="fig-fill-picker-gradient-cx"></fig-input-number>
80
+ <fig-input-number min="0" max="100" value="${this.#Q.centerY}" units="%" class="fig-fill-picker-gradient-cy"></fig-input-number>
81
81
  </div>
82
82
  <fig-tooltip text="Flip gradient">
83
83
  <fig-button icon variant="ghost" class="fig-fill-picker-gradient-flip">
@@ -86,11 +86,11 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
86
86
  </fig-tooltip>
87
87
  </fig-field>
88
88
  <fig-preview class="fig-fill-picker-gradient-preview">
89
- <fig-input-gradient class="fig-fill-picker-gradient-bar-input" edit="true" size="large" value='${JSON.stringify({type:"gradient",gradient:F(this.#X)})}'></fig-input-gradient>
89
+ <fig-input-gradient class="fig-fill-picker-gradient-bar-input" edit="true" size="large" value='${JSON.stringify({type:"gradient",gradient:V(this.#Q)})}'></fig-input-gradient>
90
90
  </fig-preview>
91
91
  <fig-field class="fig-fill-picker-gradient-interpolation">
92
92
  <label>Mixing</label>
93
- <fig-dropdown class="fig-fill-picker-gradient-space" full ${Y} value="${this.#X.interpolationSpace==="oklch"?`oklch-${this.#X.hueInterpolation||"shorter"}`:this.#X.interpolationSpace}">
93
+ <fig-dropdown class="fig-fill-picker-gradient-space" full ${X} value="${this.#Q.interpolationSpace==="oklch"?`oklch-${this.#Q.hueInterpolation||"shorter"}`:this.#Q.interpolationSpace}">
94
94
  <optgroup label="sRGB">
95
95
  <option value="srgb-linear">Linear</option>
96
96
  </optgroup>
@@ -114,31 +114,31 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
114
114
  </fig-header>
115
115
  <div class="fig-fill-picker-gradient-stops-list"></div>
116
116
  </div>
117
- `,this.#V(),this.#ZQ(Q)}#ZQ(Q){let X=Q.querySelector(".fig-fill-picker-gradient-type"),Y=(z)=>z.currentTarget?.value??z.target?.value??z.detail,Z=(z)=>{this.#X.type=Y(z),this.#V(),this.#Z()};X.addEventListener("input",Z),X.addEventListener("change",Z);let $=Q.querySelector(".fig-fill-picker-gradient-space"),j=(z)=>{let W=Y(z),_=W,B="shorter";if(W.startsWith("oklch-"))_="oklch",B=W.slice(6);this.#X=k({...this.#X,interpolationSpace:_,hueInterpolation:B}),this.#V(),this.#Z()};$?.addEventListener("input",j),$?.addEventListener("change",j),Q.querySelector(".fig-fill-picker-gradient-angle").addEventListener("input",(z)=>{let W=parseFloat(z.target.value)||0;this.#X.angle=(W+90)%360,this.#f(),this.#Z()});let U=Q.querySelector(".fig-fill-picker-gradient-cx"),L=Q.querySelector(".fig-fill-picker-gradient-cy");U?.addEventListener("input",(z)=>{this.#X.centerX=parseFloat(z.target.value)||50,this.#f(),this.#Z()}),L?.addEventListener("input",(z)=>{this.#X.centerY=parseFloat(z.target.value)||50,this.#f(),this.#Z()}),Q.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#X.stops.forEach((z)=>{z.position=100-z.position}),this.#X.stops.sort((z,W)=>z.position-W.position),this.#V(),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((W,_)=>W.position-_.position),this.#V(),this.#Z()});let K=Q.querySelector(".fig-fill-picker-gradient-bar-input");if(K){let z=(W)=>{W.stopPropagation();let _=W.detail;if(!_?.gradient)return;this.#X=k({...this.#X,..._.gradient}),this.#W(),this.#c()};K.addEventListener("input",(W)=>{z(W),this.#Z()}),K.addEventListener("change",(W)=>{z(W),this.#_()})}}#V(){if(!this.#Q)return;let Q=this.#Q.querySelector('[data-tab="gradient"]');if(!Q)return;this.#X=k(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.#f(),this.#c()}#f(){if(!this.#Q)return;let Q=this.#Q.querySelector(".fig-fill-picker-gradient-bar-input");if(Q)Q.setAttribute("value",JSON.stringify({type:"gradient",gradient:F(this.#X)}));this.#W()}#c(){if(!this.#Q)return;let Q=this.#Q.querySelector(".fig-fill-picker-gradient-stops-list");if(!Q)return;let X=Q.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(X.length===this.#X.stops.length){this.#X.stops.forEach((Y,Z)=>{let $=X[Z];$.dataset.index=Z;let j=$.querySelector(".fig-fill-picker-stop-position");if(j)j.setAttribute("value",Y.position);let J=$.querySelector(".fig-fill-picker-stop-color");if(J)J.setAttribute("value",Y.color);let U=$.querySelector(".fig-fill-picker-stop-remove");if(U)if(this.#X.stops.length<=2)U.setAttribute("disabled","");else U.removeAttribute("disabled")});return}this.#$Q(Q)}#$Q(Q){Q.innerHTML=this.#X.stops.map((X,Y)=>`
118
- <fig-field class="fig-fill-picker-gradient-stop-row" data-index="${Y}">
119
- <fig-input-number class="fig-fill-picker-stop-position" min="0" max="100" value="${X.position}" units="%"></fig-input-number>
120
- <fig-input-color class="fig-fill-picker-stop-color" text="true" alpha="true" picker="figma" picker-dialog-position="right" value="${X.color}"></fig-input-color>
121
- <fig-button icon variant="ghost" class="fig-fill-picker-stop-remove" ${this.#X.stops.length<=2?"disabled":""}>
117
+ `,this.#N(),this.#Yj(j)}#Yj(j){let Q=j.querySelector(".fig-fill-picker-gradient-type"),X=(q)=>q.currentTarget?.value??q.target?.value??q.detail,Y=(q)=>{this.#Q.type=X(q),this.#N(),this.#Y()};Q.addEventListener("input",Y),Q.addEventListener("change",Y);let Z=j.querySelector(".fig-fill-picker-gradient-space"),$=(q)=>{let W=X(q),z=W,k="shorter";if(W.startsWith("oklch-"))z="oklch",k=W.slice(6);this.#Q=O({...this.#Q,interpolationSpace:z,hueInterpolation:k}),this.#N(),this.#Y()};Z?.addEventListener("input",$),Z?.addEventListener("change",$),j.querySelector(".fig-fill-picker-gradient-angle").addEventListener("input",(q)=>{let W=parseFloat(q.target.value)||0;this.#Q.angle=(W+90)%360,this.#f(),this.#Y()});let U=j.querySelector(".fig-fill-picker-gradient-cx"),L=j.querySelector(".fig-fill-picker-gradient-cy");U?.addEventListener("input",(q)=>{this.#Q.centerX=parseFloat(q.target.value)||50,this.#f(),this.#Y()}),L?.addEventListener("input",(q)=>{this.#Q.centerY=parseFloat(q.target.value)||50,this.#f(),this.#Y()}),j.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#Q.stops.forEach((q)=>{q.position=100-q.position}),this.#Q.stops.sort((q,W)=>q.position-W.position),this.#N(),this.#Y()}),j.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#Q.stops.push({position:50,color:"#888888",opacity:100}),this.#Q.stops.sort((W,z)=>W.position-z.position),this.#N(),this.#Y()});let K=j.querySelector(".fig-fill-picker-gradient-bar-input");if(K){let q=(W)=>{W.stopPropagation();let z=W.detail;if(!z?.gradient)return;this.#Q=O({...this.#Q,...z.gradient}),this.#W(),this.#c()};K.addEventListener("input",(W)=>{q(W),this.#Y()}),K.addEventListener("change",(W)=>{q(W),this.#z()})}}#N(){if(!this.#j)return;let j=this.#j.querySelector('[data-tab="gradient"]');if(!j)return;this.#Q=O(this.#Q);let Q=j.querySelector(".fig-fill-picker-gradient-angle"),X=j.querySelector(".fig-fill-picker-gradient-center");if(this.#Q.type==="radial")Q.style.display="none",X.style.display="flex";else{Q.style.display="block",X.style.display="none";let Z=(this.#Q.angle-90+360)%360;Q.setAttribute("value",Z)}let Y=j.querySelector(".fig-fill-picker-gradient-space");if(Y)Y.value=this.#Q.interpolationSpace==="oklch"?`oklch-${this.#Q.hueInterpolation||"shorter"}`:this.#Q.interpolationSpace;this.#f(),this.#c()}#f(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-bar-input");if(j)j.setAttribute("value",JSON.stringify({type:"gradient",gradient:V(this.#Q)}));this.#W()}#c(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-stops-list");if(!j)return;let Q=j.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(Q.length===this.#Q.stops.length){this.#Q.stops.forEach((X,Y)=>{let Z=Q[Y];Z.dataset.index=Y;let $=Z.querySelector(".fig-fill-picker-stop-position");if($)$.setAttribute("value",X.position);let J=Z.querySelector(".fig-fill-picker-stop-color");if(J)J.setAttribute("value",X.color);let U=Z.querySelector(".fig-fill-picker-stop-remove");if(U)if(this.#Q.stops.length<=2)U.setAttribute("disabled","");else U.removeAttribute("disabled")});return}this.#Zj(j)}#Zj(j){j.innerHTML=this.#Q.stops.map((Q,X)=>`
118
+ <fig-field class="fig-fill-picker-gradient-stop-row" data-index="${X}">
119
+ <fig-input-number class="fig-fill-picker-stop-position" min="0" max="100" value="${Q.position}" units="%"></fig-input-number>
120
+ <fig-input-color class="fig-fill-picker-stop-color" text="true" alpha="true" picker="figma" picker-dialog-position="right" value="${Q.color}"></fig-input-color>
121
+ <fig-button icon variant="ghost" class="fig-fill-picker-stop-remove" ${this.#Q.stops.length<=2?"disabled":""}>
122
122
  <fig-icon name="minus"></fig-icon>
123
123
  </fig-button>
124
124
  </fig-field>
125
- `).join(""),Q.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach((X)=>{let Y=parseInt(X.dataset.index);X.querySelector(".fig-fill-picker-stop-position").addEventListener("input",(j)=>{this.#X.stops[Y].position=parseFloat(j.target.value)||0,this.#f(),this.#Z()});let Z=X.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});Z.addEventListener("input",(j)=>{this.#X.stops[Y].color=j.target.hexOpaque||j.target.value;let J=j.detail?.rgba?.a;if(J!==void 0)this.#X.stops[Y].opacity=Math.round(J*100);this.#f(),this.#Z()}),X.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{if(this.#X.stops.length>2)this.#X.stops.splice(Y,1),this.#V(),this.#Z()})})}#v(Q,X=!0){let Y=k({...this.#X,interpolationSpace:Q??this.#X.interpolationSpace}),Z=this.#L==="display-p3",$=Y.stops.map((J)=>{let U=(J.opacity??100)/100;return`${Z?this.#RQ(J.color,U):this.#LQ(J.color,U)} ${J.position}%`}).join(", "),j=X?` ${V(Y)}`:"";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#p=new Map;#d(Q){let X=N.#p.get(Q);if(X!==void 0)return X;let Y=document.createElement("div");Y.style.background=Q;let Z=!!Y.style.background;return N.#p.set(Q,Z),Z}#i(){let Q=this.#v(void 0,!0);if(this.#d(Q))return Q;let X=this.#v("oklab",!0);if(this.#d(X))return X;return this.#v("oklab",!1)}#jQ(){let Q=this.#Q.querySelector('[data-tab="image"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
125
+ `).join(""),j.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach((Q)=>{let X=parseInt(Q.dataset.index);Q.querySelector(".fig-fill-picker-stop-position").addEventListener("input",($)=>{this.#Q.stops[X].position=parseFloat($.target.value)||0,this.#f(),this.#Y()});let Y=Q.querySelector(".fig-fill-picker-stop-color"),Z=Y.querySelector("fig-fill-picker");if(Z)Z.anchorElement=this.#j;else requestAnimationFrame(()=>{let $=Y.querySelector("fig-fill-picker");if($)$.anchorElement=this.#j});Y.addEventListener("input",($)=>{this.#Q.stops[X].color=$.target.hexOpaque||$.target.value;let J=$.detail?.rgba?.a;if(J!==void 0)this.#Q.stops[X].opacity=Math.round(J*100);this.#f(),this.#Y()}),Q.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{if(this.#Q.stops.length>2)this.#Q.stops.splice(X,1),this.#N(),this.#Y()})})}#v(j,Q=!0){let X=O({...this.#Q,interpolationSpace:j??this.#Q.interpolationSpace}),Y=this.#L==="display-p3",Z=X.stops.map((J)=>{let U=(J.opacity??100)/100;return`${Y?this.#Rj(J.color,U):this.#Lj(J.color,U)} ${J.position}%`}).join(", "),$=Q?` ${D(X)}`:"";switch(X.type){case"linear":return`linear-gradient(${X.angle}deg${$}, ${Z})`;case"radial":return`radial-gradient(circle at ${X.centerX}% ${X.centerY}%${$}, ${Z})`;case"angular":return`conic-gradient(from ${X.angle}deg${$}, ${Z})`;default:return`linear-gradient(${X.angle}deg${$}, ${Z})`}}static#p=new Map;#d(j){let Q=M.#p.get(j);if(Q!==void 0)return Q;let X=document.createElement("div");X.style.background=j;let Y=!!X.style.background;return M.#p.set(j,Y),Y}#l(){let j=this.#v(void 0,!0);if(this.#d(j))return j;let Q=this.#v("oklab",!0);if(this.#d(Q))return Q;return this.#v("oklab",!1)}#$j(){let j=this.#j.querySelector('[data-tab="image"]'),Q=this.getAttribute("experimental"),X=Q?`experimental="${Q}"`:"";j.innerHTML=`
126
126
  <fig-field class="fig-fill-picker-media-header">
127
- <fig-dropdown class="fig-fill-picker-scale-mode" ${Y} value="${this.#j.scaleMode}">
127
+ <fig-dropdown class="fig-fill-picker-scale-mode" ${X} value="${this.#$.scaleMode}">
128
128
  <option value="fill" selected>Fill</option>
129
129
  <option value="fit">Fit</option>
130
130
  <option value="crop">Crop</option>
131
131
  <option value="tile">Tile</option>
132
132
  </fig-dropdown>
133
- <fig-input-number class="fig-fill-picker-scale" min="1" max="200" value="${this.#j.scale}" units="%" ${this.#j.scaleMode==="tile"?"":'style="display: none;"'}></fig-input-number>
133
+ <fig-input-number class="fig-fill-picker-scale" min="1" max="200" value="${this.#$.scale}" units="%" ${this.#$.scaleMode==="tile"?"":'style="display: none;"'}></fig-input-number>
134
134
  <fig-button class="fig-fill-picker-media-rotate" icon variant="ghost" aria-label="Rotate">
135
135
  <fig-icon name="rotate"></fig-icon>
136
136
  </fig-button>
137
137
  </fig-field>
138
138
  <fig-image class="fig-fill-picker-media-preview fig-fill-picker-image-preview" upload="true" label="Upload from computer" size="auto" aspect-ratio="1/1" fit="cover" checkerboard="true"></fig-image>
139
- `,this.#JQ(Q)}#JQ(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.#E(Z),this.#W(),this.#Z()}),Y.addEventListener("input",($)=>{this.#j.scale=parseFloat($.target.value)||100,this.#E(Z),this.#W(),this.#Z()}),Z.addEventListener("loaded",($)=>{let j=$.detail?.src||Z.src;if(!j)return;this.#j.url=j,this.#E(Z),this.#W(),this.#Z()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#j.url=null,this.#E(Z),this.#W(),this.#Z()}),this.#E(Z)}#E(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}}#I(Q){if(Q.tagName==="FIG-MEDIA"){if(!this.#J.url){Q.removeAttribute("src"),Q.classList.remove("has-media");return}Q.setAttribute("src",this.#J.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.#J.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.#J.scaleMode){case"fill":case"crop":Q.style.objectFit="cover";break;case"fit":Q.style.objectFit="contain";break}}#KQ(){let Q=this.#Q.querySelector('[data-tab="video"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
139
+ `,this.#Jj(j)}#Jj(j){let Q=j.querySelector(".fig-fill-picker-scale-mode"),X=j.querySelector(".fig-fill-picker-scale"),Y=j.querySelector(".fig-fill-picker-image-preview");Q.addEventListener("change",(Z)=>{this.#$.scaleMode=Z.target.value,X.style.display=Z.target.value==="tile"?"block":"none",this.#y(Y),this.#W(),this.#Y()}),X.addEventListener("input",(Z)=>{this.#$.scale=parseFloat(Z.target.value)||100,this.#y(Y),this.#W(),this.#Y()}),Y.addEventListener("loaded",(Z)=>{let $=Z.detail?.src||Y.src;if(!$)return;this.#$.url=$,this.#y(Y),this.#W(),this.#Y()}),Y.addEventListener("change",()=>{if(Y.src)return;this.#$.url=null,this.#y(Y),this.#W(),this.#Y()}),this.#y(Y)}#y(j){if(!this.#$.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.#$.url),j.classList.add("has-media"),j.style.backgroundImage="",j.style.backgroundPosition="",j.style.backgroundRepeat="",j.style.backgroundSize="",j.mediaEl?.style.removeProperty("opacity");let Q=j.querySelector("fig-input-file[data-generated]");if(Q)Q.setAttribute("label","Replace"),Q.removeAttribute("url");switch(this.#$.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.#$.url})`,j.style.backgroundPosition="top left",j.style.backgroundSize=`${this.#$.scale}%`,j.style.backgroundRepeat="repeat",j.mediaEl)j.mediaEl.style.opacity="0";break}}#C(j){if(j.tagName==="FIG-MEDIA"){if(!this.#J.url){j.removeAttribute("src"),j.classList.remove("has-media");return}j.setAttribute("src",this.#J.url),j.classList.add("has-media");let Q=j.querySelector("fig-input-file[data-generated]");if(Q)Q.setAttribute("label","Replace"),Q.removeAttribute("url");switch(this.#J.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.#J.scaleMode){case"fill":case"crop":j.style.objectFit="cover";break;case"fit":j.style.objectFit="contain";break}}#Kj(){let j=this.#j.querySelector('[data-tab="video"]'),Q=this.getAttribute("experimental"),X=Q?`experimental="${Q}"`:"";j.innerHTML=`
140
140
  <fig-field class="fig-fill-picker-media-header">
141
- <fig-dropdown class="fig-fill-picker-scale-mode" ${Y} value="${this.#J.scaleMode}">
141
+ <fig-dropdown class="fig-fill-picker-scale-mode" ${X} value="${this.#J.scaleMode}">
142
142
  <option value="fill" selected>Fill</option>
143
143
  <option value="fit">Fit</option>
144
144
  <option value="crop">Crop</option>
@@ -148,9 +148,9 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
148
148
  </fig-button>
149
149
  </fig-field>
150
150
  <fig-media class="fig-fill-picker-media-preview fig-fill-picker-video-preview" type="video" upload="true" label="Upload from computer" size="auto" aspect-ratio="1/1" fit="cover" checkerboard="true" autoplay="true" muted="true" loop="true"></fig-media>
151
- `,this.#WQ(Q)}#WQ(Q){let X=Q.querySelector(".fig-fill-picker-scale-mode"),Y=Q.querySelector(".fig-fill-picker-video-preview");X.addEventListener("change",(Z)=>{this.#J.scaleMode=Z.target.value,this.#I(Y),this.#W(),this.#Z()}),Y.addEventListener("loaded",(Z)=>{let $=Z.detail?.src||Y.src;if(!$)return;this.#J.url=$,this.#I(Y),Y.play?.(),this.#W(),this.#Z()}),Y.addEventListener("change",()=>{if(Y.src)return;this.#J.url=null,this.#I(Y),this.#W(),this.#Z()}),this.#I(Y)}#UQ(){let Q=this.#Q.querySelector('[data-tab="webcam"]'),X=this.getAttribute("experimental"),Y=X?`experimental="${X}"`:"";Q.innerHTML=`
151
+ `,this.#Wj(j)}#Wj(j){let Q=j.querySelector(".fig-fill-picker-scale-mode"),X=j.querySelector(".fig-fill-picker-video-preview");Q.addEventListener("change",(Y)=>{this.#J.scaleMode=Y.target.value,this.#C(X),this.#W(),this.#Y()}),X.addEventListener("loaded",(Y)=>{let Z=Y.detail?.src||X.src;if(!Z)return;this.#J.url=Z,this.#C(X),X.play?.(),this.#W(),this.#Y()}),X.addEventListener("change",()=>{if(X.src)return;this.#J.url=null,this.#C(X),this.#W(),this.#Y()}),this.#C(X)}#Uj(){let j=this.#j.querySelector('[data-tab="webcam"]'),Q=this.getAttribute("experimental"),X=Q?`experimental="${Q}"`:"";j.innerHTML=`
152
152
  <fig-field class="fig-fill-picker-webcam-camera" style="display: none;">
153
- <fig-dropdown class="fig-fill-picker-camera-select" full ${Y}>
153
+ <fig-dropdown class="fig-fill-picker-camera-select" full ${X}>
154
154
  </fig-dropdown>
155
155
  </fig-field>
156
156
  <fig-video class="fig-fill-picker-webcam-preview" aspect-ratio="1/1" fit="cover" checkerboard="true" autoplay="true" muted="true">
@@ -164,4 +164,4 @@ import{gradientToValueShape as F,gradientInterpolationClause as V,normalizeGradi
164
164
  Capture
165
165
  </fig-button>
166
166
  </div>
167
- `,this.#zQ(Q)}#zQ(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(U=null)=>{try{let L={video:U?{deviceId:{exact:U}}:!0};if(this.#K.stream)this.#K.stream.getTracks().forEach((W)=>W.stop());this.#K.stream=await navigator.mediaDevices.getUserMedia(L),X.srcObject=this.#K.stream,X.style.display="block",Y.style.display="none";let z=(await navigator.mediaDevices.enumerateDevices()).filter((W)=>W.kind==="videoinput");if(z.length>1){if($.style.display="",j.querySelectorAll(":scope > option, :scope > optgroup").forEach((W)=>W.remove()),z.forEach((W,_)=>{let B=document.createElement("option");B.value=W.deviceId;let M=W.label||(z.length>1?`Camera ${_+1}`:"Camera");B.textContent=M.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(q,R)=>{return` ${/^\d+$/.test(R)?Number.parseInt(R,10).toString():R.replace(/^0+/,"")||"0"}`}),j.append(B)}),U)j.value=U}else $.style.display="none",j.querySelectorAll(":scope > option, :scope > optgroup").forEach((W)=>W.remove())}catch(L){console.error("Webcam error:",L.name,L.message);let K="Camera access denied";if(L.name==="NotAllowedError")K="Camera permission denied";else if(L.name==="NotFoundError")K="No camera found";else if(L.name==="NotReadableError")K="Camera in use by another app";else if(L.name==="OverconstrainedError")K="Camera constraints not supported";else if(!window.isSecureContext)K="Camera requires secure context";Y.innerHTML=`<span>${K}</span>`,Y.style.display="flex",X.style.display="none"}};this.#P=new MutationObserver(()=>{if(Q.style.display!=="none"&&!this.#K.stream)J()}),this.#P.observe(Q,{attributes:!0,attributeFilter:["style"]}),j.addEventListener("change",(U)=>{J(U.target.value)}),Z.addEventListener("click",async()=>{if(!this.#K.stream)return;if(!X.videoWidth||!X.videoHeight)return;let U=document.createElement("canvas");U.width=X.videoWidth,U.height=X.videoHeight,U.getContext("2d").drawImage(X,0,0,U.width,U.height);let L=await new Promise((z)=>U.toBlob(z,"image/png"));if(!L)return;if(this.#K.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#K.snapshot);this.#K.snapshot=URL.createObjectURL(L),this.#j.url=this.#K.snapshot;let K=this.#Q.querySelector(".fig-fill-picker-image-preview");if(K)this.#E(K);this.#x("image")})}#l(Q){let X=Q.h/360,Y=Q.s/100,Z=Q.v/100,$,j,J,U=Math.floor(X*6),L=X*6-U,K=Z*(1-Y),z=Z*(1-L*Y),W=Z*(1-(1-L)*Y);switch(U%6){case 0:$=Z,j=W,J=K;break;case 1:$=z,j=Z,J=K;break;case 2:$=K,j=Z,J=W;break;case 3:$=K,j=z,J=Z;break;case 4:$=W,j=K,J=Z;break;case 5:$=Z,j=K,J=z;break}return{r:Math.round($*255),g:Math.round(j*255),b:Math.round(J*255)}}#S(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,U=0,L=$===0?0:J/$,K=$;if($!==j){switch($){case X:U=(Y-Z)/J+(Y<Z?6:0);break;case Y:U=(Z-X)/J+2;break;case Z:U=(X-Y)/J+4;break}U/=6}return{h:U*360,s:L*100,v:K*100,a:1}}#k(Q){if(!Q||typeof Q.h!=="number"||typeof Q.s!=="number"||typeof Q.v!=="number")return"#D9D9D9";let X=this.#l(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)}`}#C(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.#S({r:X,g:Y,b:Z})}#LQ(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})`}#RQ(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})`}#qQ(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,U,L=($+j)/2;if($===j)J=U=0;else{let K=$-j;switch(U=L>0.5?K/(2-$-j):K/($+j),$){case X:J=((Y-Z)/K+(Y<Z?6:0))/6;break;case Y:J=((Z-X)/K+2)/6;break;case Z:J=((X-Y)/K+4)/6;break}}return{h:J*360,s:U*100,l:L*100}}#_Q(Q){let X=Q.h/360,Y=Q.s/100,Z=Q.l/100,$,j,J;if(Y===0)$=j=J=Z;else{let U=(z,W,_)=>{if(_<0)_+=1;if(_>1)_-=1;if(_<0.16666666666666666)return z+(W-z)*6*_;if(_<0.5)return W;if(_<0.6666666666666666)return z+(W-z)*(0.6666666666666666-_)*6;return z},L=Z<0.5?Z*(1+Y):Z+Y-Z*Y,K=2*Z-L;$=U(K,L,X+0.3333333333333333),j=U(K,L,X),J=U(K,L,X-0.3333333333333333)}return{r:Math.round($*255),g:Math.round(j*255),b:Math.round(J*255)}}#n(Q){let X=(W)=>{return W=W/255,W<=0.04045?W/12.92:Math.pow((W+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*$,U=0.0883024619*Y+0.2817188376*Z+0.6299787005*$,L=Math.cbrt(j),K=Math.cbrt(J),z=Math.cbrt(U);return{l:0.2104542553*L+0.793617785*K-0.0040720468*z,a:1.9779984951*L-2.428592205*K+0.4505937099*z,b:0.0259040371*L+0.7827717662*K-0.808675766*z}}#OQ(Q){let X=this.#n(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}}#r(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,U=(L)=>{let K=L<=0.0031308?12.92*L:1.055*Math.pow(L,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,K))*255)};return{r:U(4.0767416621*$-3.3077115913*j+0.2309699292*J),g:U(-1.2684380046*$+2.6097574011*j-0.3413193965*J),b:U(-0.0041960863*$-0.7034186147*j+1.707614701*J)}}#BQ(Q){let X=Q.h*Math.PI/180;return this.#r({l:Q.l,a:Q.c*Math.cos(X),b:Q.c*Math.sin(X)})}#Z(){this.#W(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#_(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let Q={type:this.#U,colorSpace:this.#L};switch(this.#U){case"solid":return{...Q,color:this.#k(this.#Y),alpha:this.#Y.a,hsv:{...this.#Y}};case"gradient":return{...Q,gradient:F(this.#X),css:this.#i()};case"image":return{...Q,image:{...this.#j}};case"video":return{...Q,video:{...this.#J}};case"webcam":return{...Q,image:{url:this.#K.snapshot,scaleMode:"fill",scale:50}};default:return{...Q,...this.#A[this.#U]}}}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.#h(),this.#W(),this.#Q){if(!this.#M){if(this.#q(),this.#D(),this.#N)this.#N.setAttribute("value",this.#Y.h);if(this.#B)this.#B.setAttribute("value",this.#Y.a*100),this.#B.setAttribute("color",this.#k(this.#Y))}}break;case"disabled":break}}}customElements.define("fig-fill-picker",N);
167
+ `,this.#qj(j)}#qj(j){let Q=j.querySelector(".fig-fill-picker-webcam-video"),X=j.querySelector(".fig-fill-picker-webcam-status"),Y=j.querySelector(".fig-fill-picker-webcam-capture"),Z=j.querySelector(".fig-fill-picker-webcam-camera"),$=j.querySelector(".fig-fill-picker-camera-select"),J=async(U=null)=>{try{let L={video:U?{deviceId:{exact:U}}:!0};if(this.#K.stream)this.#K.stream.getTracks().forEach((W)=>W.stop());this.#K.stream=await navigator.mediaDevices.getUserMedia(L),Q.srcObject=this.#K.stream,Q.style.display="block",X.style.display="none";let q=(await navigator.mediaDevices.enumerateDevices()).filter((W)=>W.kind==="videoinput");if(q.length>1){if(Z.style.display="",$.querySelectorAll(":scope > option, :scope > optgroup").forEach((W)=>W.remove()),q.forEach((W,z)=>{let k=document.createElement("option");k.value=W.deviceId;let F=W.label||(q.length>1?`Camera ${z+1}`:"Camera");k.textContent=F.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(_,R)=>{return` ${/^\d+$/.test(R)?Number.parseInt(R,10).toString():R.replace(/^0+/,"")||"0"}`}),$.append(k)}),U)$.value=U}else Z.style.display="none",$.querySelectorAll(":scope > option, :scope > optgroup").forEach((W)=>W.remove())}catch(L){console.error("Webcam error:",L.name,L.message);let K="Camera access denied";if(L.name==="NotAllowedError")K="Camera permission denied";else if(L.name==="NotFoundError")K="No camera found";else if(L.name==="NotReadableError")K="Camera in use by another app";else if(L.name==="OverconstrainedError")K="Camera constraints not supported";else if(!window.isSecureContext)K="Camera requires secure context";X.innerHTML=`<span>${K}</span>`,X.style.display="flex",Q.style.display="none"}};this.#P=new MutationObserver(()=>{if(j.style.display!=="none"&&!this.#K.stream)J()}),this.#P.observe(j,{attributes:!0,attributeFilter:["style"]}),$.addEventListener("change",(U)=>{J(U.target.value)}),Y.addEventListener("click",async()=>{if(!this.#K.stream)return;if(!Q.videoWidth||!Q.videoHeight)return;let U=document.createElement("canvas");U.width=Q.videoWidth,U.height=Q.videoHeight,U.getContext("2d").drawImage(Q,0,0,U.width,U.height);let L=await new Promise((q)=>U.toBlob(q,"image/png"));if(!L)return;if(this.#K.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#K.snapshot);this.#K.snapshot=URL.createObjectURL(L),this.#$.url=this.#K.snapshot;let K=this.#j.querySelector(".fig-fill-picker-image-preview");if(K)this.#y(K);this.#x("image")})}#i(j){let Q=j.h/360,X=j.s/100,Y=j.v/100,Z,$,J,U=Math.floor(Q*6),L=Q*6-U,K=Y*(1-X),q=Y*(1-L*X),W=Y*(1-(1-L)*X);switch(U%6){case 0:Z=Y,$=W,J=K;break;case 1:Z=q,$=Y,J=K;break;case 2:Z=K,$=Y,J=W;break;case 3:Z=K,$=q,J=Y;break;case 4:Z=W,$=K,J=Y;break;case 5:Z=Y,$=K,J=q;break}return{r:Math.round(Z*255),g:Math.round($*255),b:Math.round(J*255)}}#A(j){let Q=j.r/255,X=j.g/255,Y=j.b/255,Z=Math.max(Q,X,Y),$=Math.min(Q,X,Y),J=Z-$,U=0,L=Z===0?0:J/Z,K=Z;if(Z!==$){switch(Z){case Q:U=(X-Y)/J+(X<Y?6:0);break;case X:U=(Y-Q)/J+2;break;case Y:U=(Q-X)/J+4;break}U/=6}return{h:U*360,s:L*100,v:K*100,a:1}}#O(j){if(!j||typeof j.h!=="number"||typeof j.s!=="number"||typeof j.v!=="number")return"#D9D9D9";let Q=this.#i(j),X=(Y)=>{return(isNaN(Y)?217:Math.max(0,Math.min(255,Math.round(Y)))).toString(16).padStart(2,"0")};return`#${X(Q.r)}${X(Q.g)}${X(Q.b)}`}#I(j){let Q=parseInt(j.slice(1,3),16),X=parseInt(j.slice(3,5),16),Y=parseInt(j.slice(5,7),16);return this.#A({r:Q,g:X,b:Y})}#Lj(j,Q=1){let X=parseInt(j.slice(1,3),16),Y=parseInt(j.slice(3,5),16),Z=parseInt(j.slice(5,7),16);return`rgba(${X}, ${Y}, ${Z}, ${Q})`}#Rj(j,Q=1){let X=+(parseInt(j.slice(1,3),16)/255).toFixed(4),Y=+(parseInt(j.slice(3,5),16)/255).toFixed(4),Z=+(parseInt(j.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${X} ${Y} ${Z} / ${Q})`}#_j(j){let Q=j.r/255,X=j.g/255,Y=j.b/255,Z=Math.max(Q,X,Y),$=Math.min(Q,X,Y),J,U,L=(Z+$)/2;if(Z===$)J=U=0;else{let K=Z-$;switch(U=L>0.5?K/(2-Z-$):K/(Z+$),Z){case Q:J=((X-Y)/K+(X<Y?6:0))/6;break;case X:J=((Y-Q)/K+2)/6;break;case Y:J=((Q-X)/K+4)/6;break}}return{h:J*360,s:U*100,l:L*100}}#zj(j){let Q=j.h/360,X=j.s/100,Y=j.l/100,Z,$,J;if(X===0)Z=$=J=Y;else{let U=(q,W,z)=>{if(z<0)z+=1;if(z>1)z-=1;if(z<0.16666666666666666)return q+(W-q)*6*z;if(z<0.5)return W;if(z<0.6666666666666666)return q+(W-q)*(0.6666666666666666-z)*6;return q},L=Y<0.5?Y*(1+X):Y+X-Y*X,K=2*Y-L;Z=U(K,L,Q+0.3333333333333333),$=U(K,L,Q),J=U(K,L,Q-0.3333333333333333)}return{r:Math.round(Z*255),g:Math.round($*255),b:Math.round(J*255)}}#r(j){let Q=(W)=>{return W=W/255,W<=0.04045?W/12.92:Math.pow((W+0.055)/1.055,2.4)},X=Q(j.r),Y=Q(j.g),Z=Q(j.b),$=0.4122214708*X+0.5363325363*Y+0.0514459929*Z,J=0.2119034982*X+0.6806995451*Y+0.1073969566*Z,U=0.0883024619*X+0.2817188376*Y+0.6299787005*Z,L=Math.cbrt($),K=Math.cbrt(J),q=Math.cbrt(U);return{l:0.2104542553*L+0.793617785*K-0.0040720468*q,a:1.9779984951*L-2.428592205*K+0.4505937099*q,b:0.0259040371*L+0.7827717662*K-0.808675766*q}}#Bj(j){let Q=this.#r(j);return{l:Q.l,c:Math.sqrt(Q.a*Q.a+Q.b*Q.b),h:(Math.atan2(Q.b,Q.a)*180/Math.PI+360)%360}}#n(j){let Q=j.l+0.3963377774*j.a+0.2158037573*j.b,X=j.l-0.1055613458*j.a-0.0638541728*j.b,Y=j.l-0.0894841775*j.a-1.291485548*j.b,Z=Q*Q*Q,$=X*X*X,J=Y*Y*Y,U=(L)=>{let K=L<=0.0031308?12.92*L:1.055*Math.pow(L,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,K))*255)};return{r:U(4.0767416621*Z-3.3077115913*$+0.2309699292*J),g:U(-1.2684380046*Z+2.6097574011*$-0.3413193965*J),b:U(-0.0041960863*Z-0.7034186147*$+1.707614701*J)}}#kj(j){let Q=j.h*Math.PI/180;return this.#n({l:j.l,a:j.c*Math.cos(Q),b:j.c*Math.sin(Q)})}#Y(){this.#W(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#z(){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let j={type:this.#U,colorSpace:this.#L};switch(this.#U){case"solid":return{...j,color:this.#O(this.#X),alpha:this.#X.a,hsv:{...this.#X}};case"gradient":return{...j,gradient:V(this.#Q),css:this.#l()};case"image":return{...j,image:{...this.#$}};case"video":return{...j,video:{...this.#J}};case"webcam":return{...j,image:{url:this.#K.snapshot,scaleMode:"fill",scale:50}};default:return{...j,...this.#S[this.#U]}}}set value(j){if(typeof j==="string")this.setAttribute("value",j);else this.setAttribute("value",JSON.stringify(j))}attributeChangedCallback(j,Q,X){if(Q===X)return;switch(j){case"value":if(this.#h(),this.#W(),this.#j){if(!this.#F){if(this.#_(),this.#G(),this.#M)this.#M.setAttribute("value",this.#X.h);if(this.#k)this.#k.setAttribute("value",this.#X.a*100),this.#k.setAttribute("color",this.#O(this.#X))}}break;case"disabled":break}}}customElements.define("fig-fill-picker",M);