@rogieking/figui3 8.9.19 → 8.9.21
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.
- package/.cursor/skills/fig-lab/SKILL.md +4 -3
- package/.cursor/skills/propkit/SKILL.md +1 -1
- package/README.md +26 -4
- package/components.css +40 -10
- package/dist/components.css +1 -1
- package/dist/fig-editor.js +3 -3
- package/dist/fig-lab.css +1 -1
- package/dist/fig-lab.js +2 -2
- package/dist/fig.css +1 -1
- package/dist/fig.js +4 -4
- package/fig-editor.js +125 -5
- package/fig-lab.css +46 -8
- package/fig-lab.js +497 -2
- package/fig.js +29 -8
- package/package.json +1 -1
package/dist/fig-editor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import"./fig.js";import"./fig-lab.js";function A(J,Q){if(!customElements.get(J))customElements.define(J,Q)}function
|
|
1
|
+
import"./fig.js";import"./fig-lab.js";function A(J,Q){if(!customElements.get(J))customElements.define(J,Q)}function T(J,Q){return J.hasAttribute(Q)&&J.getAttribute(Q)!=="false"}function d(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}function I(J){if(!J)return"";return`url("${String(J).replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}")`}function C(J,Q={}){let Z=document.createElement("fig-icon");if(J)Z.setAttribute("name",J);if(Q.size)Z.setAttribute("size",Q.size);if(Q.className)Z.className=Q.className;return Z}function v(J,Q){let Z=($)=>{if($===null||$===void 0||$===!1)return;if(Array.isArray($)){$.forEach(Z);return}J.append($ instanceof Node?$:String($))};return Z(Q),J}function p(J,Q={}){for(let[Z,$]of Object.entries(Q)){if($===null||$===void 0||$===!1)continue;if(Z==="className")J.className=String($);else if($===!0)J.setAttribute(Z,"");else J.setAttribute(Z,String($))}return J}function G(J,Q,Z){let $=document.createElement(J);return p($,Q),v($,Z)}var s="http://www.w3.org/2000/svg";function u(J,Q,Z){let $=document.createElementNS(s,J);for(let[X,Y]of Object.entries(Q||{})){if(Y===null||Y===void 0||Y===!1)continue;if(X==="className")$.setAttribute("class",String(Y));else if(Y===!0)$.setAttribute(X,"");else $.setAttribute(X,String(Y))}return v($,Z)}function i(J){let Q=String(J||"").replace(/^#/,"");return{r:parseInt(Q.substring(0,2),16)||0,g:parseInt(Q.substring(2,4),16)||0,b:parseInt(Q.substring(4,6),16)||0}}function r(J,Q,Z){let $=J/255,X=Q/255,Y=Z/255,j=Math.max($,X,Y),K=Math.min($,X,Y),U=(j+K)/2;if(j===K)return{h:0,s:0,l:U*100};let z=j-K,L=U>0.5?z/(2-j-K):z/(j+K),W;switch(j){case $:W=((X-Y)/z+(X<Y?6:0))/6;break;case X:W=((Y-$)/z+2)/6;break;default:W=(($-X)/z+4)/6;break}return{h:W*360,s:L*100,l:U*100}}function x(J){let Q=J/255;return Q<=0.04045?Q/12.92:Math.pow((Q+0.055)/1.055,2.4)}function l(J,Q,Z){let $=x(J),X=x(Q),Y=x(Z),j=Math.cbrt(0.4122214708*$+0.5363325363*X+0.0514459929*Y),K=Math.cbrt(0.2119034982*$+0.6806995451*X+0.1073969566*Y),U=Math.cbrt(0.0883024619*$+0.2817188376*X+0.6299787005*Y);return{l:0.2104542553*j+0.793617785*K-0.0040720468*U,a:1.9779984951*j-2.428592205*K+0.4505937099*U,b:0.0259040371*j+0.7827717662*K-0.808675766*U}}function o(J,Q,Z){return{l:J,c:Math.sqrt(Q*Q+Z*Z),h:Math.atan2(Z,Q)*180/Math.PI}}function n({owner:J,onStart:Q,onEnd:Z,startClass:$="",endClass:X="",chevronClass:Y="",startLabel:j="Scroll back",endLabel:K="Scroll forward"}={}){let U=(z,L)=>{let W=document.createElement("button");if(W.type="button",W.className=["fig-overflow",`fig-overflow-${z}`,z==="start"?$:X].filter(Boolean).join(" "),W.dataset.figOverflow=z,J)W.setAttribute(`data-fig-${J}-nav`,z);return W.setAttribute("tabindex","-1"),W.setAttribute("aria-label",z==="start"?j:K),W.appendChild(C("chevron",{size:"small",className:["fig-overflow-chevron",Y].filter(Boolean).join(" ")})),W.addEventListener("click",(O)=>{O.preventDefault(),O.stopPropagation(),L?.(O)}),W};return{start:U("start",Q),end:U("end",Z)}}function w(J,Q,Z="x",$=2){if(!J||!Q)return!1;let X=Z==="x",Y=X?Q.scrollWidth:Q.scrollHeight,j=X?Q.clientWidth:Q.clientHeight,K=X?Q.scrollLeft:Q.scrollTop,U=Y-j>$,z=!U||K<=$,L=!U||K+j>=Y-$;return J.classList.toggle("overflow-start",!z),J.classList.toggle("overflow-end",!L),U}function b(J,Q="x",Z=1){if(!J)return;let $=Q==="x",Y=($?J.clientWidth:J.clientHeight)*0.8*Z;J.scrollBy({[$?"left":"top"]:Y,behavior:"smooth"})}function a(J,Q,Z="y",$="auto"){if(!J||!Q||!J.contains(Q))return;requestAnimationFrame(()=>{if(!J.isConnected||!Q.isConnected)return;let X=Z==="x",Y=X?J.scrollWidth:J.scrollHeight,j=X?J.clientWidth:J.clientHeight;if(Y<=j+1){w(J,J,Z);return}let K=Q.getBoundingClientRect(),U=J.getBoundingClientRect(),z=X?J.scrollLeft:J.scrollTop,L=(X?K.left-U.left:K.top-U.top)+z,W=X?K.width:K.height,O=Y-j,f=Math.max(0,Math.min(L+W/2-j/2,O));J.scrollTo({[X?"left":"top"]:f,behavior:$}),w(J,J,Z)})}function t(J){let Q=J||"";if(Q.startsWith("["))try{let $=JSON.parse(Q);return Array.isArray($)?$:[]}catch{}let Z=Q.includes(`
|
|
2
2
|
`)?`
|
|
3
|
-
`:",";return Q.split(Z).map(($)=>$.trim()).filter(Boolean)}function e(J){if(J&&typeof J==="object")return String(J.value??J.label??"");return String(J??"")}function JJ(J){if(J&&typeof J==="object")return String(J.label??J.value??"");return String(J??"")}class
|
|
3
|
+
`:",";return Q.split(Z).map(($)=>$.trim()).filter(Boolean)}function e(J){if(J&&typeof J==="object")return String(J.value??J.label??"");return String(J??"")}function JJ(J){if(J&&typeof J==="object")return String(J.label??J.value??"");return String(J??"")}class h extends HTMLElement{static get observedAttributes(){return["value","disabled","selected","label"]}get value(){let J=this.getAttribute("value");if(J!==null)return J;return(this.textContent||"").trim()}set value(J){if(J===null||J===void 0)this.removeAttribute("value");else this.setAttribute("value",String(J))}get disabled(){return T(this,"disabled")}set disabled(J){if(J)this.setAttribute("disabled","");else this.removeAttribute("disabled")}get selected(){return T(this,"selected")}set selected(J){if(J)this.setAttribute("selected","");else this.removeAttribute("selected")}connectedCallback(){if(!this.hasAttribute("role"))this.setAttribute("role","option");if(!this.hasAttribute("tabindex"))this.setAttribute("tabindex","-1");this.#K()}attributeChangedCallback(J,Q,Z){if(Q===Z)return;if(J==="disabled")this.#K()}#K(){if(this.disabled)this.setAttribute("aria-disabled","true"),this.setAttribute("tabindex","-1");else if(this.removeAttribute("aria-disabled"),!this.hasAttribute("tabindex"))this.setAttribute("tabindex","-1")}}A("fig-select-option",h);class m extends HTMLElement{#K=null;#Y=null;#j=null;#W=this.syncOverflow.bind(this);connectedCallback(){if(!this.hasAttribute("slot"))this.setAttribute("slot","panel");this.#J(),this.#_(),this.#R(),this.addEventListener("scroll",this.#W,{passive:!0}),this.#j?.disconnect(),this.#j=new ResizeObserver(()=>this.syncOverflow()),this.#j.observe(this),requestAnimationFrame(()=>this.syncOverflow())}disconnectedCallback(){this.removeEventListener("scroll",this.#W),this.#j?.disconnect(),this.#j=null,this.#U()}syncOverflow(){return this.#_(),w(this,this,"y")}scrollToOption(J,Q="auto"){a(this,J,"y",Q)}#J(){let J=this.querySelector(":scope > fig-chooser");if(!J)return;while(J.firstChild)this.insertBefore(J.firstChild,J);J.remove()}#_(){let J=Array.from(this.children).find((Q)=>!Q.hasAttribute("data-fig-select-nav"));if(J?.tagName==="FIG-SEPARATOR")J.setAttribute("borderless","")}#R(){if(this.#K&&this.#Y&&this.contains(this.#K)&&this.contains(this.#Y))return;this.#U();let J=n({owner:"select",startLabel:"Scroll up",endLabel:"Scroll down",onStart:()=>b(this,"y",-1),onEnd:()=>b(this,"y",1)});this.#K=J.start,this.#Y=J.end,this.prepend(this.#K),this.append(this.#Y)}#U(){this.#K?.remove(),this.#Y?.remove(),this.#K=null,this.#Y=null,this.classList.remove("overflow-start","overflow-end")}}A("fig-select-options",m);class c extends HTMLElement{#K=null;#Y=null;#j=null;#W=null;#J=null;#_=null;#R=!1;#U=-1;#k=!1;#$=!1;#L=null;#Q=!1;#z=null;#X=null;#Z=!1;#w=this.#TJ.bind(this);#F=this.#kJ.bind(this);#N=this.#MJ.bind(this);#V=this.#n.bind(this);#u=this.#S.bind(this);#q=this.#HJ.bind(this);static get observedAttributes(){return["value","disabled","label","options","position","offset","closedby","open","variant"]}get value(){return this.getAttribute("value")??""}set value(J){if(J===null||J===void 0)this.removeAttribute("value");else this.setAttribute("value",String(J))}get open(){return T(this,"open")}set open(J){if(J)this.setAttribute("open","");else this.removeAttribute("open")}connectedCallback(){if(!this.#R)this.#m();if(this.#M(),this.#C(),this.#zJ(),this.#UJ(),this.#B(),this.#WJ(),this.#BJ(),this.open)this.#s()}disconnectedCallback(){this.#qJ(),document.removeEventListener("keydown",this.#V,!0),this.#_?.disconnect(),this.#_=null}attributeChangedCallback(J,Q,Z){if(Q===Z||!this.#R)return;if(J==="options"){this.#C(),this.#B();return}if(J==="value"||J==="label"){this.#B();return}if(J==="disabled"){this.#zJ();return}if(J==="open"){if(Z===null||Z==="false")this.#NJ();else this.#s();return}if(J==="position"||J==="offset"||J==="closedby")this.#UJ()}focus(J){this.#K?.focus(J)}blur(){this.#K?.blur()}#H(J){return J?.nodeType===1&&(J.tagName==="FIG-SELECT-OPTION"||J.tagName==="FIG-SEPARATOR"||J.tagName==="FIG-SELECT-OPTIONS")}#M(){for(let J of this.querySelectorAll(":scope > fig-select-options"))if(!J.hasAttribute("slot"))J.setAttribute("slot","panel")}#f(){let Q=(this.#J?.assignedElements({flatten:!0})??[]).find((Z)=>Z.tagName==="FIG-SELECT-OPTIONS");if(Q)return Q;return this.querySelector(":scope > fig-select-options")}#D(){return Boolean(this.querySelector(":scope > fig-select-option:not([data-fig-generated]), :scope > fig-select-options > fig-select-option:not([data-fig-generated])"))}#T(){let J=this.#f();if(J){if(!J.hasAttribute("slot"))J.setAttribute("slot","panel");return J}return J=document.createElement("fig-select-options"),J.setAttribute("slot","panel"),J.setAttribute("data-fig-generated",""),this.appendChild(J),J}#C(){if(this.#D())return;let J=this.hasAttribute("options"),Q=J?this.#T():this.#f();if(!Q)return;this.#Z=!0;try{for(let X of Q.querySelectorAll(":scope > fig-select-option[data-fig-generated]"))X.remove();if(!J)return;let Z=t(this.getAttribute("options")),$=Q.querySelector(":scope > .fig-overflow-end");for(let X of Z){let Y=document.createElement("fig-select-option");if(Y.setAttribute("data-fig-generated",""),Y.setAttribute("value",e(X)),Y.textContent=JJ(X),$)Q.insertBefore(Y,$);else Q.appendChild(Y)}}finally{this.#Z=!1}}#m(){this.#R=!0;let J=this.attachShadow({mode:"open"}),Q=document.createElement("style");Q.textContent=`
|
|
4
4
|
:host {
|
|
5
5
|
display: inline-flex;
|
|
6
6
|
position: relative;
|
|
@@ -87,4 +87,4 @@ import"./fig.js";import"./fig-lab.js";function A(J,Q){if(!customElements.get(J))
|
|
|
87
87
|
min-height: 0;
|
|
88
88
|
max-height: inherit;
|
|
89
89
|
}
|
|
90
|
-
`,J.appendChild(Q);let Z=document.createElement("fig-button");Z.className="fig-select-trigger",Z.setAttribute("part","trigger"),Z.setAttribute("variant","ghost"),Z.setAttribute("aria-haspopup","listbox"),Z.setAttribute("aria-expanded","false");let $=document.createElement("span");$.className="fig-select-prepend",$.setAttribute("part","prepend"),$.setAttribute("aria-hidden","true");let X=document.createElement("span");X.className="fig-select-label",X.setAttribute("part","label"),Z.append($,X);let Y=document.createElement("dialog",{is:"fig-popup"});if(Y.setAttribute("is","fig-popup"),Y.setAttribute("part","listbox"),Y.setAttribute("theme","menu"),Y.setAttribute("role","listbox"),"popover"in HTMLElement.prototype)Y.setAttribute("popover","manual");Y.id=d(),Z.setAttribute("aria-controls",Y.id);let j=document.createElement("slot");if(j.setAttribute("name","panel"),Y.appendChild(j),J.append(Z,Y),this.#j=Z,this.#K=$,this.#W=X,this.#Y=Y,this.#J=j,Y.anchor=Z,this.#M(),this.#l(),!this.hasAttribute("value")){let K=this.#v().find((U)=>k(U,"selected"));if(K)this.setAttribute("value",K.value)}}#l(){if(!this.#Y||this.#Z)return;if(typeof this.#Y.positionPopup!=="function")return;this.#G=this.#Y.positionPopup.bind(this.#Y),this.#Y.positionPopup=()=>{if(!this.open){this.#G?.();return}this.#zJ()},this.#Z=!0}#w(J){if(!J)return null;let Q=document.createRange();Q.selectNodeContents(J);let Z=[...Q.getClientRects()].filter(($)=>$.width>0&&$.height>0);if(Z.length)return Z[0];return J.getBoundingClientRect()}#o(){if(typeof this.#Y?.parseViewportMargins==="function")return this.#Y.parseViewportMargins();return{top:8,right:8,bottom:8,left:8}}#d(){let J=this.#W?.getBoundingClientRect();if(!J)return null;return{x:J.x,y:J.y,width:J.width,height:J.height}}#p(){let J=window.visualViewport;return{width:J?.width??window.innerWidth,height:J?.height??window.innerHeight,offsetLeft:J?.offsetLeft??0,offsetTop:J?.offsetTop??0}}#u(J,Q,Z=0.25){if(!J&&!Q)return!1;if(!J||!Q)return!0;return Math.abs(J.x-Q.x)>Z||Math.abs(J.y-Q.y)>Z||Math.abs(J.width-Q.width)>Z||Math.abs(J.height-Q.height)>Z}#b(J,Q,Z=0.25){if(!J&&!Q)return!1;if(!J||!Q)return!0;return Math.abs(J.width-Q.width)>Z||Math.abs(J.height-Q.height)>Z||Math.abs(J.offsetLeft-Q.offsetLeft)>Z||Math.abs(J.offsetTop-Q.offsetTop)>Z}#n(){if(!this.#Q)return!1;let J=this.#u(this.#z,this.#d()),Q=this.#b(this.#X,this.#p());return!J&&!Q}#YJ(){this.#z=this.#d(),this.#X=this.#p()}#zJ(){if(this.#n())return;let J=this.#Y,Q=this.#W;if(!J||!Q){this.#G?.();return}let Z=this.#v(),$=Z.find((R)=>this.#D(R)===this.value)||Z[0];if(!$){this.#G?.();return}this.#G?.();let X=J.getBoundingClientRect(),Y=Q.getBoundingClientRect(),j=this.#w($);if(!X.width||!X.height||!Y.width||!j)return;let K=j.left-X.left,U=j.top-X.top,G=k(this,"full")?this.getBoundingClientRect().left:Y.left-K,W=Y.top-U,O=this.#o();if(typeof J.clampToViewport==="function")({left:G,top:W}=J.clampToViewport({left:G,top:W},X,O));else{let{left:R,top:_}=O,T=window.innerWidth-X.width-O.right,L=window.innerHeight-X.height-O.bottom;G=Math.min(Math.max(G,R),Math.max(R,T)),W=Math.min(Math.max(W,_),Math.max(_,L))}J.style.setProperty("right","auto","important"),J.style.setProperty("bottom","auto","important"),J.style.setProperty("left",`${Math.round(G)}px`,"important"),J.style.setProperty("top",`${Math.round(W)}px`,"important");let V=this.#V(),H=this.#w($);if(H&&V&&V.scrollHeight>V.clientHeight+1){let R=H.top-Y.top;if(Math.abs(R)>0.5)V.scrollTop+=R;V.syncOverflow?.()}if(this.#Q||this.open)this.#YJ()}#HJ(){this.#j?.addEventListener("click",this.#I),this.#j?.addEventListener("keydown",this.#f),this.addEventListener("click",this.#_),this.addEventListener("pointerover",this.#F),this.#Y?.addEventListener("keydown",this.#f),this.#Y?.addEventListener("close",this.#H),this.#J?.addEventListener("slotchange",this.#T)}#BJ(){this.#j?.removeEventListener("click",this.#I),this.#j?.removeEventListener("keydown",this.#f),this.removeEventListener("click",this.#_),this.removeEventListener("pointerover",this.#F),this.#Y?.removeEventListener("keydown",this.#f),this.#Y?.removeEventListener("close",this.#H),this.#J?.removeEventListener("slotchange",this.#T)}#jJ(){this.#M(),this.#h()}#RJ(){if(this.#R)return;this.#R=new MutationObserver((J)=>{if(this.#k||this.#$)return;let Q=!1;for(let Z of J){if(Z.type==="childList"){if([...Z.addedNodes].some(($)=>this.#B($))||[...Z.removedNodes].some(($)=>this.#B($))||Z.target?.closest?.("fig-select-option"))Q=!0}if(Z.type==="attributes"&&Z.target?.tagName==="FIG-SELECT-OPTION"){if(Z.attributeName==="value"||Z.attributeName==="disabled"||Z.attributeName==="label")Q=!0;else if(Z.attributeName==="selected"){if(k(Z.target,"selected")){let $=this.#D(Z.target);if((this.getAttribute("value")??"")!==$)this.setAttribute("value",$),Q=!0}else if(this.#D(Z.target)===(this.getAttribute("value")??""))Q=!0}}if(Z.type==="characterData"&&Z.target?.parentElement?.tagName==="FIG-SELECT-OPTION")Q=!0}if(Q)this.#h()}),this.#R.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","disabled","selected","label"]})}#v({enabledOnly:J=!1}={}){let Q=this.#V(),Z=Q?Array.from(Q.querySelectorAll(":scope > fig-select-option")):[];if(!J)return Z;return Z.filter(($)=>!k($,"disabled"))}#D(J){if(!J)return"";if(typeof J.value==="string")return J.value;let Q=J.getAttribute?.("value");if(Q!=null)return Q;return(J.textContent||"").trim()}#y(J){if(!J)return"";let Q=J.getAttribute?.("label");if(Q!=null&&Q!=="")return Q.trim();let Z=[];for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE){let j=$.textContent?.trim();if(j)Z.push(j);continue}if(!($ instanceof Element))continue;let X=$.getAttribute("slot");if(X==="prepend"||X==="append")continue;let Y=$.textContent?.trim();if(Y)Z.push(Y)}if(Z.length)return Z.join(" ").trim();return(J.textContent||"").trim()}#_J(J){if(!this.#K)return;let Q=J?.querySelector?.(':scope > [slot="prepend"]');this.#K.replaceChildren(...Array.from(Q?.childNodes??[],(Z)=>Z.cloneNode(!0)))}#OJ(){if(!this.#Y)return;this.#Y.setAttribute("position",this.getAttribute("position")||"bottom left");let J=this.getAttribute("offset");if(J)this.#Y.setAttribute("offset",J);else this.#Y.removeAttribute("offset");let Q=this.getAttribute("closedby");if(Q)this.#Y.setAttribute("closedby",Q);else this.#Y.removeAttribute("closedby")}#fJ(){let J=k(this,"disabled");if(this.#j)if(J)this.#j.setAttribute("disabled","");else this.#j.removeAttribute("disabled");if(J&&this.open)this.open=!1}#a(J){if(!J.length)return null;let Q=J.find((Z)=>k(Z,"selected"));if(Q&&!k(Q,"disabled"))return Q;return J.find((Z)=>!k(Z,"disabled"))||J[0]||null}#E(J){this.dispatchEvent(new CustomEvent("input",{detail:J,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:J,bubbles:!0,composed:!0}))}#h(){if(this.#k)return;this.#k=!0;try{let J=this.#v(),Q=this.hasAttribute("value"),Z=Q?this.getAttribute("value"):null,$=Q?J.find((K)=>this.#D(K)===Z):null,X=!1;if(!$){if(Q){if(!J.length){if(this.#W)this.#W.textContent=Z||this.getAttribute("label")||"";return}if($=this.#a(J),$){let K=this.#D($);if(Z!==K)this.setAttribute("value",K),X=!0}else this.removeAttribute("value"),X=!0}else if($=J.find((K)=>k(K,"selected")),$)this.setAttribute("value",this.#D($)),X=!0}for(let K of J){let U=K===$;if(K.setAttribute("aria-selected",U?"true":"false"),U)K.setAttribute("selected","");else K.removeAttribute("selected")}let Y=$&&this.#y($)||this.getAttribute("label")||"";if(this.#W)this.#W.textContent=Y;this.#_J($);let j=this.getAttribute("label")||"Select";if(this.#j?.setAttribute("aria-label",j),this.#V()?.syncOverflow?.(),X)this.#E(this.getAttribute("value")??"")}finally{this.#k=!1}}#kJ(J){if(k(this,"disabled"))return;J.preventDefault(),J.stopPropagation();let Q=!this.open;if(Q&&this.#Y&&this.#j)this.#Y.anchor=this.#j;this.open=Q}#GJ(J){let Z=(typeof J.composedPath==="function"?J.composedPath():[]).find(($)=>$?.tagName==="FIG-SELECT-OPTION");if(!Z||!this.contains(Z))return;if(k(Z,"disabled"))return;this.#LJ(Z)}#L(J){let Z=(typeof J.composedPath==="function"?J.composedPath():[]).find(($)=>$?.tagName==="FIG-SELECT-OPTION");if(!Z||!this.contains(Z))return;if(k(Z,"disabled"))return;if(J.relatedTarget instanceof Node&&Z.contains(J.relatedTarget))return;this.dispatchEvent(new CustomEvent("optionhover",{detail:this.#D(Z),bubbles:!0,composed:!0}))}#KJ(J){if(J.currentTarget===document&&J.key!=="Escape")return;if(!(this.open&&(this.#Y?.matches?.(":open")??!1))){if(this.#j?.contains(J.target)&&(J.key==="ArrowDown"||J.key==="Enter"||J.key===" ")){if(J.preventDefault(),this.#Y&&this.#j)this.#Y.anchor=this.#j;this.open=!0,requestAnimationFrame(()=>{let X=this.#v({enabledOnly:!0}).findIndex((Y)=>this.#D(Y)===this.value);this.#N(X>=0?X:0)})}return}let Z=this.#v({enabledOnly:!0});if(!Z.length)return;switch(J.key){case"ArrowDown":J.preventDefault(),this.#JJ(),this.#N(this.#U+1);break;case"ArrowUp":J.preventDefault(),this.#JJ(),this.#N(this.#U-1);break;case"Home":J.preventDefault(),this.#N(0);break;case"End":J.preventDefault(),this.#N(Z.length-1);break;case"Escape":J.preventDefault(),this.open=!1,this.#j?.focus();break;case"Enter":case" ":{this.#JJ();let $=Z[this.#U];if(!$)return;J.preventDefault(),this.#LJ($);break}}}#t(){if(this.hasAttribute("open"))this.removeAttribute("open");this.#j?.setAttribute("aria-expanded","false"),this.#j?.focus(),this.#U=-1}#LJ(J){let Q=this.#D(J);this.setAttribute("value",Q),this.#h(),this.#E(Q),this.open=!1}#e(){return this.#v({enabledOnly:!0})}#JJ(){let J=this.#e();if(!J.length){this.#U=-1;return}let Q=J.find(($)=>$===document.activeElement),Z=Q?J.indexOf(Q):-1;this.#U=Z>=0?Z:this.#U}#N(J){let Q=this.#e();if(!Q.length)return;let Z=(J%Q.length+Q.length)%Q.length;this.#U=Z,Q[Z]?.focus()}#VJ(){if(!this.#Y||!this.#j)return;let J=Math.ceil(this.getBoundingClientRect().width),Q=Math.ceil(this.#j.getBoundingClientRect().width),Z=Math.max(J,Q,96);this.#Y.style.setProperty("width","max-content","important"),this.#Y.style.setProperty("min-width",`${Z}px`,"important"),this.#Y.style.setProperty("max-width","min(20rem, calc(100vw - 1rem))","important")}#s(){if(!this.#Y||k(this,"disabled"))return;if(this.#j)this.#Y.anchor=this.#j;this.#l(),this.#Q=!1,this.#z=null,this.#X=null,this.#h(),this.#VJ(),this.#Y.open=!0,document.addEventListener("keydown",this.#f,!0),this.#j?.setAttribute("aria-expanded","true"),this.#U=-1,requestAnimationFrame(()=>{this.#VJ(),this.#zJ();let J=this.#V(),Z=this.#e().findIndex(($)=>this.#D($)===this.value);if(Z>=0)this.#N(Z);else if(this.#j?.hasAttribute("data-focus-visible")||this.#j?.matches?.(":focus-visible"))this.#N(0);J?.syncOverflow?.(),this.#Q=!0,this.#YJ()})}#TJ(){if(!this.#Y)return;this.#Q=!1,this.#z=null,this.#X=null,document.removeEventListener("keydown",this.#f,!0),this.#Y.open=!1,this.#j?.setAttribute("aria-expanded","false")}}A("fig-select",c);var QJ=["srgb","srgb-linear","display-p3","oklab","oklch","hsl"],ZJ=["shorter","longer","increasing","decreasing"],E=new Set(["oklch","hsl"]);function y(J){let Q={...J??{}},Z=String(Q.interpolationSpace??"srgb").toLowerCase();if(!QJ.includes(Z))Z="srgb";Q.interpolationSpace=Z;let $=String(Q.hueInterpolation??"shorter").toLowerCase();return Q.hueInterpolation=ZJ.includes($)?$:"shorter",Q}function S(J){let Q=y(J);return Q.interpolationSpace="srgb",delete Q.hueInterpolation,Q}function P(J){let Q=S(J),Z={...Q,interpolationSpace:Q.interpolationSpace};if(E.has(Q.interpolationSpace))Z.hueInterpolation=Q.hueInterpolation;else delete Z.hueInterpolation;return Z}function $J(J){let Q=y(J);if(Q.interpolationSpace==="srgb")return"";if(E.has(Q.interpolationSpace))return`in ${Q.interpolationSpace} ${Q.hueInterpolation} hue`;return`in ${Q.interpolationSpace}`}function v(J){let Q=y(J);if(E.has(Q.interpolationSpace))return`${Q.interpolationSpace}-${Q.hueInterpolation||"shorter"}`;return Q.interpolationSpace}function D(J){let Q=String(J??"");for(let Z of E){let $=`${Z}-`;if(Q.startsWith($))return{interpolationSpace:Z,hueInterpolation:Q.slice($.length)||"shorter"}}return{interpolationSpace:Q||"srgb",hueInterpolation:"shorter"}}var XJ=0;class N extends HTMLElement{static#j=[{value:"srgb",space:"srgb",title:"Classic",subtitle:"sRGB Linear"},{value:"oklab",space:"oklab",title:"Smooth",subtitle:"OKLab"},{value:"oklch-increasing",space:"oklch",title:"Vibrant",subtitle:"OKLCH Increasing"},{value:"hsl-increasing",space:"hsl",title:"Vivid",subtitle:"HSL Increasing"},{value:"oklch-decreasing",space:"oklch",title:"Vibrant",subtitle:"OKLCH Decreasing",advanced:!0},{value:"hsl-decreasing",space:"hsl",title:"Vivid",subtitle:"HSL Decreasing",advanced:!0}];static#Y(J){let Q=N.#j,Z=Q.find((K)=>K.value===J);if(Z)return Z;let $=D(J),X=Q.find((K)=>K.space===$.interpolationSpace),Y=X?.subtitle.split(" ")[0]??$.interpolationSpace.toUpperCase(),j=$.hueInterpolation;return{value:J,space:$.interpolationSpace,title:X?.title??"Custom",subtitle:E.has($.interpolationSpace)?`${Y} ${j.charAt(0).toUpperCase()}${j.slice(1)}`:Y}}#K=null;#W=null;#J=null;#R=`fig-fill-picker-dialog-${++XJ}`;#q="solid";anchorElement=null;#U="solid";#k="srgb";#Z={h:0,s:0,v:85,a:1};#G="hex";#Q={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}]};#z={url:null,scaleMode:"fill",scale:50};#X={url:null,poster:null,scaleMode:"fill",scale:50,opacity:1,missing:!0};#$={stream:null,live:!0,snapshot:null,deviceId:null,scaleMode:"fill",scale:50,opacity:1};#I=null;#_={};#F={};#f=null;#H=null;#T=null;#B=null;#M=!1;#V=!1;#C=null;#A=null;#c=null;#x=null;#l=null;#w=0;#o=null;#d=null;#p=new Set;#u=new Set;constructor(){super();this.#o=this.#h.bind(this),this.#d=this.#kJ.bind(this)}static get observedAttributes(){return["value","disabled","alpha","mode","webcam-mode","default-video","aria-label","aria-labelledby","aria-describedby"]}connectedCallback(){this.style.display="contents",this.#y(()=>{this.#fJ(),this.#GJ(),this.#L()})}disconnectedCallback(){if(this.#e({stopWebcam:!0}),this.#_J(),this.#OJ(),this.#W)this.#W.removeAttribute("selected");if(this.#K)this.#K.removeEventListener("click",this.#o),this.#K.removeEventListener("keydown",this.#d);this.#K=null,this.#W=null}#b(){return this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false"}#n(){return this.getAttribute("webcam-mode")==="snapshot"?"snapshot":"live"}#YJ(){return this.#U==="webcam"&&this.#n()==="live"&&this.#$.live!==!1}#zJ(){return{live:this.#n()==="live"&&this.#$.live!==!1,snapshot:this.#$.snapshot??null,deviceId:this.#$.deviceId??null,scaleMode:this.#$.scaleMode||"fill",scale:this.#$.scale??50,opacity:this.#$.opacity??1}}#HJ(){let J=this.#X.url??null;return{url:J,poster:this.#X.poster??null,scaleMode:this.#X.scaleMode||"fill",scale:this.#X.scale??50,opacity:this.#X.opacity??1,...J?{}:{missing:!0}}}#BJ(J){if(J.webcam&&typeof J.webcam==="object"){let{stream:Q,...Z}=J.webcam;Object.assign(this.#$,Z);return}if(J.type==="webcam"&&J.image){if(J.image.url!=null)this.#$.snapshot=J.image.url;if(J.image.scaleMode)this.#$.scaleMode=J.image.scaleMode;if(J.image.scale!=null)this.#$.scale=J.image.scale}}#jJ(){this.dispatchEvent(new CustomEvent("webcamstream",{bubbles:!0,composed:!0,detail:{stream:this.#$.stream,deviceId:this.#$.deviceId??null}}))}get webcamStream(){return this.#$.stream}releaseWebcam(){this.#N()}#RJ(J){if(!J)return null;if(this.#$.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#$.snapshot),this.#u.delete(this.#$.snapshot);return this.#$.snapshot=URL.createObjectURL(J),this.#u.add(this.#$.snapshot),this.#$.snapshot}async#v(J){if(!J?.videoWidth||!J.videoHeight)return null;let Q=document.createElement("canvas");Q.width=J.videoWidth,Q.height=J.videoHeight,Q.getContext("2d").drawImage(J,0,0,Q.width,Q.height);let Z=await new Promise(($)=>Q.toBlob($,"image/png"));return this.#RJ(Z)}#D(J){if(this.#U!=="webcam")return;let Q=this.#$.stream;if(!Q)return;if(this.#I===Q&&this.#$.snapshot){this.#L();return}this.#I=Q,this.#v(J).then((Z)=>{if(!Z||this.#U!=="webcam"||this.#$.stream!==Q)return;this.#L(),this.#O()})}#y(J){let Q=requestAnimationFrame(()=>{if(this.#p.delete(Q),this.isConnected)J()});return this.#p.add(Q),Q}#_J(){this.#p.forEach((J)=>cancelAnimationFrame(J)),this.#p.clear()}#OJ(){let J=new Set([this.#$.snapshot,this.#X.poster,this.#z.url].filter((Q)=>typeof Q==="string"&&Q.startsWith("blob:")));this.#u.forEach((Q)=>{if(!J.has(Q))URL.revokeObjectURL(Q)}),this.#u.clear(),J.forEach((Q)=>this.#u.add(Q))}#fJ(){let J=Array.from(this.children).find((Q)=>!Q.getAttribute("slot")?.startsWith("mode-"));if(!J)this.#W=document.createElement("fig-swatch"),this.#W.setAttribute("background","#D9D9D9"),this.appendChild(this.#W),this.#K=this.#W;else if(J.matches("fig-swatch, fig-chit"))this.#W=J,this.#K=J;else this.#K=J,this.#W=null;if(this.#E(),this.#K.removeEventListener("click",this.#o),this.#K.addEventListener("click",this.#o),this.#K.removeEventListener("keydown",this.#d),this.#K.addEventListener("keydown",this.#d),this.#W)this.#y(()=>{let Q=this.#W.querySelector('input[type="color"]');if(Q)Q.remove();this.#E()})}#a(){return this.getAttribute("aria-label")||"Fill picker"}#E(){if(!this.#K)return;let J=this.#b(),Q=this.getAttribute("aria-labelledby");if(!this.#K.hasAttribute("role"))this.#K.setAttribute("role","button");if(this.#K.setAttribute("tabindex",J?"-1":"0"),this.#K.setAttribute("aria-disabled",J?"true":"false"),this.#K.setAttribute("aria-haspopup","dialog"),this.#K.setAttribute("aria-expanded",this.#J?.open?"true":"false"),this.#K.setAttribute("aria-controls",this.#R),this.#K.removeAttribute("aria-hidden"),Q)this.#K.setAttribute("aria-labelledby",Q),this.#K.removeAttribute("aria-label");else if(this.hasAttribute("aria-label"))this.#K.setAttribute("aria-label",`Open ${this.#a()}`),this.#K.removeAttribute("aria-labelledby");else if(this.#K.removeAttribute("aria-labelledby"),!this.#K.hasAttribute("aria-label"))this.#K.setAttribute("aria-label",`Open ${this.#a()}`);let Z=this.getAttribute("aria-describedby");if(Z)this.#K.setAttribute("aria-describedby",Z);else this.#K.removeAttribute("aria-describedby")}#h(J){if(this.#b())return;J.stopPropagation(),J.preventDefault(),this.#t()}#kJ(J){if(J.key!=="Enter"&&J.key!==" ")return;if(this.#b())return;J.preventDefault(),J.stopPropagation(),this.#t()}#GJ(){let J=this.getAttribute("value");if(!J)return;let Q=["solid","gradient","image","video","webcam"];try{let Z=JSON.parse(J);if(Z.type)this.#U=Z.type;if(Z.color){if(typeof Z.color==="string")this.#Z=this.#XJ(Z.color);else if(typeof Z.color==="object"&&Z.color.h!==void 0)this.#Z=Z.color}let $=Z.alpha!==void 0?Number(Z.alpha):Z.opacity!==void 0?Number(Z.opacity)/100:void 0;if(Number.isFinite($))this.#Z.a=Math.max(0,Math.min(1,$));if(this.#k="srgb",Z.gradient)this.#Q=S({...this.#Q,...Z.gradient});if(Z.image)this.#z={...this.#z,...Z.image};if(Z.video)this.#X={...this.#X,...Z.video},this.#X.missing=!this.#X.url;if(this.#BJ(Z),Z.type&&!Q.includes(Z.type)){let{type:X,...Y}=Z;this.#F[Z.type]=Y}}catch(Z){if(J.startsWith("#"))this.#U="solid",this.#Z=this.#XJ(J)}}#L(){if(!this.#W)return;let J,Q="cover",Z="center";switch(this.#U){case"solid":J=this.#m(this.#Z);break;case"gradient":J=this.#uJ();break;case"image":if(this.#z.url){J=I(this.#z.url);let $=this.#KJ(this.#z.scaleMode,this.#z.scale);Q=$.size,Z=$.position}else J="";break;case"video":if(this.#X.poster){J=I(this.#X.poster);let $=this.#KJ(this.#X.scaleMode,this.#X.scale);Q=$.size,Z=$.position}else J="";break;case"webcam":if(this.#$.snapshot){J=I(this.#$.snapshot);let $=this.#KJ(this.#$.scaleMode,this.#$.scale);Q=$.size,Z=$.position}else J="";break;default:{J=(this.#_[this.#U]?.element||this.querySelector(`[slot="mode-${this.#U}"]`))?.getAttribute("swatch-background")||"";break}}if(this.#W.setAttribute("background",J),this.#W.style.setProperty("--swatch-bg-size",Q),this.#W.style.setProperty("--swatch-bg-position",Z),this.#U==="solid")this.#W.setAttribute("alpha",this.#Z.a);else this.#W.removeAttribute("alpha")}#KJ(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"}}}#t(){if(this.#b())return;if(!this.#J)this.#VJ();if(this.#c=JSON.stringify(this.value),this.#x=this.#c,this.#s(this.#U,{emit:!1}),this.#W)this.#W.setAttribute("selected","true");this.#J.open=!0,this.#E(),this.#y(()=>{this.#J?.querySelector(".fig-fill-picker-close, .fig-fill-picker-type, fig-button, button, input, [tabindex='0']")?.focus?.(),this.#y(()=>{this.#i(),this.#g()})})}open(){this.#t()}close(){if(this.#J)this.#J.open=!1,this.#E()}#LJ(){if(!this.#J)return;for(let[J,{element:Q}]of Object.entries(this.#_)){let Z=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find(($)=>$.dataset.tab===J);if(!Z)continue;while(Z.firstChild)Q.appendChild(Z.firstChild)}}#e({stopWebcam:J=!1}={}){if(this.#C)this.#C(),this.#C=null;if(this.#A?.disconnect(),this.#A=null,!J&&this.#YJ())this.#JJ();else this.#N();if(!this.#J)return;this.#LJ(),this.#J.remove(),this.#J=null,this.#l=null,this.#c=null,this.#x=null,this.#f=null,this.#H=null,this.#T=null,this.#B=null,this.#V=!1,this.#E()}#JJ(){this.#w+=1;let J=this.#J?.querySelector(".fig-fill-picker-webcam-video");if(J)J.srcObject=null}#N({emit:J=!0}={}){this.#w+=1;let Q=Boolean(this.#$.stream);if(this.#$.stream)this.#$.stream.getTracks().forEach(($)=>$.stop()),this.#$.stream=null;this.#I=null;let Z=this.#J?.querySelector(".fig-fill-picker-webcam-video");if(Z)Z.srcObject=null;if(Q&&J)this.#jJ()}#VJ(){this.#_={},this.querySelectorAll('[slot^="mode-"]').forEach((O)=>{let V=O.getAttribute("slot").slice(5);this.#_[V]={element:O,label:O.getAttribute("label")||V.charAt(0).toUpperCase()+V.slice(1)}}),this.#J=document.createElement("dialog",{is:"fig-popup"}),this.#J.setAttribute("is","fig-popup"),this.#J.id=this.#R,this.#J.setAttribute("aria-label",this.#a()),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.#K;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"],Z={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},$=this.getAttribute("mode"),X;if($){if(X=$.split(",").map((V)=>V.trim().toLowerCase()).filter((V)=>Q.includes(V)||this.#_[V]),X.length===0)X=[...Q]}else X=[...Q];let Y={...Z};for(let[O,{label:V}]of Object.entries(this.#_))Y[O]=V;if(!X.includes(this.#U))this.#U=X[0],this.#q=X[0];let j;if(X.length===1)j=f("h3",{className:"fig-fill-picker-type-label"},Y[X[0]]);else{let O=f("fig-select-options",{},X.map((V)=>f("fig-select-option",{value:V},Y[V])));j=f("fig-select",{className:"fig-fill-picker-type",label:"Fill type",variant:"ghost",value:this.#U},O)}let K=X.map((O)=>f("div",{className:"fig-fill-picker-tab","data-tab":O})),U=f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-close","aria-label":"Close fill picker"},C("close"));this.#J.replaceChildren(f("fig-header",{},[j,U]),f("fig-content",{},K)),document.body.appendChild(this.#J);for(let[O,{element:V}]of Object.entries(this.#_)){let H=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((R)=>R.dataset.tab===O);if(!H)continue;while(V.firstChild)H.appendChild(V.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:O,container:H}}))}let z=this.#J.querySelector(".fig-fill-picker-type");if(z)z.addEventListener("change",(O)=>{let V=typeof O.detail==="string"?O.detail:O.target?.value;if(V)this.#s(V)});this.#J.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#J.open=!1});let G=()=>{if(this.#W)this.#W.removeAttribute("selected");if(this.#YJ())this.#JJ();else this.#N();let O=JSON.stringify(this.value);if(this.#x!==null&&this.#x!==O)this.#S();this.#c=null,this.#x=null,this.#E();let V=this.#K;this.#y(()=>{if(V?.isConnected)HTMLElement.prototype.focus.call(V)}),this.dispatchEvent(new CustomEvent("close"))};this.#J.addEventListener("close",G);let W={solid:()=>this.#gJ(),gradient:()=>this.#pJ(),image:()=>this.#tJ(),video:()=>this.#JQ(),webcam:()=>this.#ZQ()};for(let[O,V]of Object.entries(W))if(!this.#_[O]&&X.includes(O))V();for(let O of Object.keys(this.#_)){if(Q.includes(O))continue;let V=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((H)=>H.dataset.tab===O);if(!V)continue;V.addEventListener("input",(H)=>{if(H.target===this)return;if(H.stopPropagation(),H.detail)this.#F[O]=H.detail;this.#O()}),V.addEventListener("change",(H)=>{if(H.target===this)return;if(H.stopPropagation(),H.detail)this.#F[O]=H.detail;this.#S()})}}#s(J,{emit:Q=!0}={}){let Z=Array.from(this.#J?.querySelectorAll(".fig-fill-picker-tab")??[]).find((K)=>K.dataset.tab===J);if(!Z)return;let $=this.#q;if(this.#q=J,this.#U=J,$==="webcam"&&J!=="webcam")this.#N();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((K)=>{if(K.dataset.tab===J)K.style.display="block";else K.style.display="none"});let j=this.#J.querySelector("fig-content");if(j)j.style.padding=this.#_[J]?"0":"";if(J==="gradient")this.#y(()=>{this.#P();let K=Z.querySelector(".fig-fill-picker-gradient-bar-input");K?.refreshLayout?.(),this.#y(()=>{K?.refreshLayout?.()})});if(J==="video")this.#qJ();if(J==="webcam")this.#$.live=this.#n()==="live",this.#l?.(this.#$.deviceId);if(this.#L(),Q)this.#O()}#TJ(){if(!this.#J?.open)return;if(this.#s(this.#U,{emit:!1}),this.#i(),this.#g(),this.#QJ(),this.#T)this.#T.setAttribute("value",this.#Z.h);if(this.#B)this.#B.setAttribute("value",this.#Z.a*100),this.#B.setAttribute("color",this.#m(this.#Z));this.#P();let J=this.#J.querySelector('[data-tab="image"]'),Q=J?.querySelector(".fig-fill-picker-scale-mode"),Z=J?.querySelector(".fig-fill-picker-scale"),$=J?.querySelector(".fig-fill-picker-image-preview");if(Q)Q.value=this.#z.scaleMode;if(Z)Z.setAttribute("value",this.#z.scale),Z.style.display=this.#z.scaleMode==="tile"?"block":"none";if($)this.#r($);let X=this.#J.querySelector('[data-tab="video"]'),Y=X?.querySelector(".fig-fill-picker-scale-mode"),j=X?.querySelector(".fig-fill-picker-video-preview");if(Y)Y.value=this.#X.scaleMode;if(j)this.#ZJ(j)}#gJ(){let J=this.#J.querySelector('[data-tab="solid"]'),Q=this.getAttribute("alpha")!=="false",Z=f("canvas",{width:"200",height:"200"}),$=f("fig-handle",{"aria-label":"Color saturation and brightness",role:"slider","aria-valuemin":"0","aria-valuemax":"100",type:"color",color:this.#m({...this.#Z,a:1}),"data-no-color-picker":!0,drag:!0,"drag-surface":".fig-fill-picker-color-area","drag-axes":"x,y","drag-snapping":"modifier"}),X=f("fig-preview",{className:"fig-fill-picker-color-area"},[Z,$]),Y=f("fig-tooltip",{text:"Sample color"},f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-eyedropper","aria-label":"Sample color"},C("eyedropper"))),j=f("div",{className:`fig-fill-picker-sliders${Q?"":" is-hue-only"}`},[Y,f("fig-slider",{type:"hue",variant:"classic",text:"false",min:"0",max:"360","aria-label":"Hue",value:this.#Z.h}),Q?f("fig-slider",{type:"opacity",variant:"classic",text:"false",min:"0",max:"100","aria-label":"Opacity",value:this.#Z.a*100,color:this.#m(this.#Z)}):null]),K=f("fig-select-options",{},[["hex","Hex"],["rgb","RGB"],["css","CSS"],["hsl","HSL"],["hsb","HSB"],["lab","LAB"],["lch","LCH"]].map(([W,O])=>f("fig-select-option",{value:W},O))),U=f("fig-field",{className:"fig-fill-picker-inputs"},[f("fig-select",{className:"fig-fill-picker-input-mode",label:"Color value format",value:this.#G},K),f("span",{className:"fig-fill-picker-input-fields"})]);if(J.replaceChildren(X,j,U),this.#f=J.querySelector("canvas"),this.#H=J.querySelector("fig-handle"),this.#MJ(),this.#i(),this.#g(),this.#PJ(),this.#T=J.querySelector('fig-slider[type="hue"]'),this.#T.addEventListener("input",(W)=>{this.#Z.h=parseFloat(W.target.value),this.#i(),this.#g(),this.#QJ(),this.#O()}),this.#T.addEventListener("change",()=>{this.#S()}),Q)this.#B=J.querySelector('fig-slider[type="opacity"]'),this.#B.addEventListener("input",(W)=>{this.#Z.a=parseFloat(W.target.value)/100,this.#QJ(),this.#O()}),this.#B.addEventListener("change",()=>{this.#S()});J.querySelector(".fig-fill-picker-input-mode").addEventListener("change",(W)=>{let O=typeof W.detail==="string"?W.detail:W.target?.value;if(!O)return;this.#G=O,this.#SJ()}),this.#SJ();let G=J.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)G.addEventListener("click",async()=>{try{let O=await new EyeDropper().open();this.#Z={...this.#XJ(O.sRGBHex),a:this.#Z.a},this.#i(),this.#g(),this.#QJ(),this.#O()}catch(W){}});else G.setAttribute("disabled",""),G.title="EyeDropper not supported in this browser"}#GQ(){let J=this.#J?.querySelector('[data-tab="solid"]');if(J){let Q=J.querySelector("canvas");if(Q){let Z=document.createElement("canvas");Z.width=Q.width,Z.height=Q.height,Q.replaceWith(Z),this.#f=Z,this.#PJ()}this.#i(),this.#g()}this.#UJ(),this.#O()}#i(){if(!this.#f&&this.#J)this.#f=this.#J.querySelector('[data-tab="solid"] canvas');if(!this.#f)return;let J=this.#k==="display-p3"?"display-p3":"srgb",Q=this.#f.getContext("2d",{colorSpace:J});if(!Q)return;let Z=this.#f.width,$=this.#f.height;Q.clearRect(0,0,Z,$);let X=this.#Z.h,Y=this.#k==="display-p3",j=Q.createLinearGradient(0,0,Z,0);if(Y){j.addColorStop(0,"color(display-p3 1 1 1)");let[U,z,G]=hslToP3(X,100,50);j.addColorStop(1,`color(display-p3 ${U} ${z} ${G})`)}else j.addColorStop(0,"#FFFFFF"),j.addColorStop(1,`hsl(${X}, 100%, 50%)`);Q.fillStyle=j,Q.fillRect(0,0,Z,$);let K=Q.createLinearGradient(0,0,0,$);K.addColorStop(0,"rgba(0,0,0,0)"),K.addColorStop(1,"rgba(0,0,0,1)"),Q.fillStyle=K,Q.fillRect(0,0,Z,$)}#g(J=0){if(!this.#H||!this.#f)return;this.#MJ();let Q=this.#f.getBoundingClientRect();if((Q.width===0||Q.height===0)&&J<5){this.#y(()=>this.#g(J+1));return}let Z=Math.max(0,Math.min(100,this.#Z.s)),$=Math.max(0,Math.min(100,100-this.#Z.v));this.#H.setAttribute("value",`${Z}% ${$}%`),this.#H.setAttribute("color",this.#m({...this.#Z,a:1}))}#MJ(){if(!this.#H)return;this.#H.setAttribute("aria-valuenow",String(Math.round(this.#Z.v))),this.#H.setAttribute("aria-valuetext",`Saturation ${Math.round(this.#Z.s)}%, brightness ${Math.round(this.#Z.v)}%`),this.#H.removeAttribute("aria-pressed")}#yJ(J,Q,Z={}){let{updateHandle:$=!0,emitInput:X=!0,emitChange:Y=!1}=Z;if(this.#Z.s=Math.max(0,Math.min(100,J*100)),this.#Z.v=Math.max(0,Math.min(100,(1-Q)*100)),this.#H)this.#H.setAttribute("color",this.#m({...this.#Z,a:1})),this.#MJ();if($)this.#g();if(this.#QJ(),X)this.#O();if(Y)this.#S()}#PJ(){if(this.#C)this.#C(),this.#C=null;if(!this.#f||!this.#H)return;let J=this.#f.parentElement||this.#f,Q=this.#H,Z=!1,$=(z,G={})=>{let W=J.getBoundingClientRect();if(W.width===0||W.height===0)return;let O=Math.max(0,Math.min(z.clientX-W.left,W.width)),V=Math.max(0,Math.min(z.clientY-W.top,W.height));this.#yJ(O/W.width,V/W.height,G)},X=(z)=>{if(z.button!==0)return;if(z.target===Q||Q.contains(z.target))return;Z=!0,this.#M=!0,J.setPointerCapture(z.pointerId),$(z,{updateHandle:!0,emitInput:!0})},Y=(z)=>{if(!Z)return;if(z.buttons===0){j();return}$(z,{updateHandle:!0,emitInput:!0})},j=()=>{if(!Z)return;Z=!1,this.#M=!1,this.#S()},K=(z)=>{this.#M=!0;let G=z.detail?.px,W=z.detail?.py;if(!Number.isFinite(G)||!Number.isFinite(W))return;Q.setAttribute("value",`${G*100}% ${W*100}%`),this.#yJ(G,W,{updateHandle:!1,emitInput:!0})},U=(z)=>{let G=z.detail?.px,W=z.detail?.py;if(Number.isFinite(G)&&Number.isFinite(W))Q.setAttribute("value",`${G*100}% ${W*100}%`),this.#yJ(G,W,{updateHandle:!1,emitInput:!1});this.#M=!1,this.#S()};J.addEventListener("pointerdown",X),J.addEventListener("pointermove",Y),J.addEventListener("pointerup",j),J.addEventListener("pointercancel",j),J.addEventListener("lostpointercapture",j),Q.addEventListener("input",K),Q.addEventListener("change",U),this.#C=()=>{J.removeEventListener("pointerdown",X),J.removeEventListener("pointermove",Y),J.removeEventListener("pointerup",j),J.removeEventListener("pointercancel",j),J.removeEventListener("lostpointercapture",j),Q.removeEventListener("input",K),Q.removeEventListener("change",U),this.#M=!1}}#SJ(){let J=this.#J?.querySelector(".fig-fill-picker-input-fields");if(!J)return;let Q=(K,U)=>f("fig-tooltip",{text:K},U),Z=(K,U,z,G,W,O)=>f("fig-input-number",{className:K,"aria-label":U,min:z,max:G,step:W,units:O}),$=this.getAttribute("alpha")!=="false",X=()=>$?Q("Alpha",Z("fig-fill-picker-ci-a","Alpha",0,100,0.1,"%")):null,Y=(K,U="")=>f("div",{className:["input-combo",U].filter(Boolean).join(" ")},K),j;switch(this.#G){case"rgb":j=Y([Q("Red",Z("fig-fill-picker-ci-r","Red",0,255)),Q("Green",Z("fig-fill-picker-ci-g","Green",0,255)),Q("Blue",Z("fig-fill-picker-ci-b","Blue",0,255)),X()]);break;case"hsl":j=Y([Q("Hue",Z("fig-fill-picker-ci-h","Hue",0,360)),Q("Saturation",Z("fig-fill-picker-ci-s","Saturation",0,100)),Q("Lightness",Z("fig-fill-picker-ci-l","Lightness",0,100)),X()]);break;case"hsb":j=Y([Q("Hue",Z("fig-fill-picker-ci-h","Hue",0,360)),Q("Saturation",Z("fig-fill-picker-ci-s","Saturation",0,100)),Q("Brightness",Z("fig-fill-picker-ci-v","Brightness",0,100)),X()]);break;case"lab":j=Y([Q("Lightness",Z("fig-fill-picker-ci-okl","Lightness",0,100)),Q("Green-Red axis",Z("fig-fill-picker-ci-oka","Green-Red axis",-0.4,0.4,0.001)),Q("Blue-Yellow axis",Z("fig-fill-picker-ci-okb","Blue-Yellow axis",-0.4,0.4,0.001)),X()]);break;case"lch":j=Y([Q("Lightness",Z("fig-fill-picker-ci-okl","Lightness",0,100)),Q("Chroma",Z("fig-fill-picker-ci-okc","Chroma",0,0.4,0.001)),Q("Hue",Z("fig-fill-picker-ci-okh","Hue",0,360)),X()]);break;case"css":j=f("fig-input-text",{className:"fig-fill-picker-ci-css","aria-label":"CSS color",placeholder:"rgba(0, 0, 0, 1)"});break;default:{let K=f("fig-input-text",{className:"fig-fill-picker-ci-hex","aria-label":"Hex color",placeholder:"FFFFFF"});j=$?Y([K,X()],"fig-fill-picker-ci-hex-row"):K}break}J.replaceChildren(j),this.#mJ(),this.#y(()=>this.#QJ())}#mJ(){let J=this.#J?.querySelector(".fig-fill-picker-input-fields");if(!J)return;let Q=()=>{if(this.#M)return;let X=this.#dJ();if(!X)return;let Y=Number.isFinite(X.a)?X.a:this.#Z.a;if(this.#Z={...X,a:Y},this.#i(),this.#g(),this.#T)this.#T.setAttribute("value",this.#Z.h);if(this.#B&&Number.isFinite(X.a))this.#B.setAttribute("value",this.#Z.a*100);this.#O()},Z=()=>this.#S();J.querySelectorAll("fig-input-number, fig-input-text").forEach((X)=>{X.addEventListener("input",Q),X.addEventListener("change",Z)})}#cJ(){let J=this.#J?.querySelector(".fig-fill-picker-ci-a");if(!J)return;let Q=parseFloat(J.value);if(!Number.isFinite(Q))return;return Math.max(0,Math.min(1,Q/100))}#dJ(){let J=($)=>this.#J?.querySelector(`.${$}`),Q=($)=>parseFloat(J($)?.value??0),Z=($)=>{if(!$)return null;let X=this.#cJ();return{...$,a:X??$.a??this.#Z.a}};switch(this.#G){case"rgb":return Z(this.#$J({r:Q("fig-fill-picker-ci-r"),g:Q("fig-fill-picker-ci-g"),b:Q("fig-fill-picker-ci-b")}));case"hsl":{let $=this.#zQ({h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),l:Q("fig-fill-picker-ci-l")});return Z(this.#$J($))}case"hsb":return Z({h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),v:Q("fig-fill-picker-ci-v")});case"lab":{let $=this.#hJ({l:Q("fig-fill-picker-ci-okl")/100,a:Q("fig-fill-picker-ci-oka"),b:Q("fig-fill-picker-ci-okb")});return Z(this.#$J($))}case"lch":{let $=this.#fQ({l:Q("fig-fill-picker-ci-okl")/100,c:Q("fig-fill-picker-ci-okc"),h:Q("fig-fill-picker-ci-okh")});return Z(this.#$J($))}case"css":{let $=J("fig-fill-picker-ci-css");if(!$)return null;return this.#KQ($.value)}default:{let $=J("fig-fill-picker-ci-hex");if(!$)return null;let X=$.value.replace(/^#/,"");if(X.length===3)X=X[0]+X[0]+X[1]+X[1]+X[2]+X[2];if(X.length===8){let Y=parseInt(X.slice(6,8),16)/255;if(X=X.slice(0,6),!/^[0-9a-fA-F]{6}$/.test(X))return null;return{...this.#XJ(`#${X}`),a:Y}}if(X.length!==6||!/^[0-9a-fA-F]{6}$/.test(X))return null;return Z(this.#XJ(`#${X}`))}}}#QJ(){if(!this.#J)return;let J=this.#m(this.#Z),Q=this.#AJ(this.#Z),Z=(X)=>this.#J.querySelector(`.${X}`),$=(X,Y)=>{let j=Z(X);if(j)j.setAttribute("value",Y)};switch(this.#G){case"rgb":$("fig-fill-picker-ci-r",Q.r),$("fig-fill-picker-ci-g",Q.g),$("fig-fill-picker-ci-b",Q.b);break;case"hsl":{let X=this.#UQ(Q);$("fig-fill-picker-ci-h",Math.round(X.h)),$("fig-fill-picker-ci-s",Math.round(X.s)),$("fig-fill-picker-ci-l",Math.round(X.l));break}case"hsb":$("fig-fill-picker-ci-h",Math.round(this.#Z.h)),$("fig-fill-picker-ci-s",Math.round(this.#Z.s)),$("fig-fill-picker-ci-v",Math.round(this.#Z.v));break;case"lab":{let X=this.#vJ(Q);$("fig-fill-picker-ci-okl",Math.round(X.l*100)),$("fig-fill-picker-ci-oka",+X.a.toFixed(3)),$("fig-fill-picker-ci-okb",+X.b.toFixed(3));break}case"lch":{let X=this.#OQ(Q);$("fig-fill-picker-ci-okl",Math.round(X.l*100)),$("fig-fill-picker-ci-okc",+X.c.toFixed(3)),$("fig-fill-picker-ci-okh",Math.round(X.h));break}case"css":$("fig-fill-picker-ci-css",this.#jQ(this.#Z));break;default:$("fig-fill-picker-ci-hex",J.replace(/^#/,"").toUpperCase());break}if(this.#G!=="css"){let X=Math.round(this.#Z.a*1000)/10;$("fig-fill-picker-ci-a",Number.isInteger(X)?X:+X.toFixed(1))}if(this.#B)this.#B.setAttribute("color",J);this.#L()}#pJ(){let J=this.#J.querySelector('[data-tab="gradient"]'),Q=f("fig-select",{className:"fig-fill-picker-gradient-type",label:"Gradient type",value:this.#Q.type},f("fig-select-options",{},[["linear","Linear"],["radial","Radial"],["angular","Angular"]].map(([z,G])=>f("fig-select-option",{value:z},G)))),Z=(z,G,W)=>f("fig-tooltip",{text:z},f("fig-button",{icon:!0,variant:"ghost",className:G,"aria-label":z},C(W))),$=f("div",{className:"fig-fill-picker-gradient-actions"},[Z("Flip gradient","fig-fill-picker-gradient-flip","swap"),Z("Rotate gradient","fig-fill-picker-gradient-rotate","rotate")]),X=f("fig-field",{className:"fig-fill-picker-gradient-header"},[Q,$]),Y=f("fig-input-gradient",{className:"fig-fill-picker-gradient-bar-input","aria-label":"Gradient stops",edit:"true",mode:"tip",size:"large",value:JSON.stringify({type:"gradient",gradient:P(this.#Q)})}),j=f("fig-preview",{className:"fig-fill-picker-gradient-preview"},Y),K=f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-gradient-add","aria-label":"Add gradient stop",title:"Add stop"},C("add")),U=f("div",{className:"fig-fill-picker-gradient-stops"},[f("fig-header",{className:"fig-fill-picker-gradient-stops-header",borderless:!0},[f("span",{},"Stops"),K]),f("div",{className:"fig-fill-picker-gradient-stops-list"},document.createElement("fig-reorder"))]);J.replaceChildren(X,j,U),this.#P(),this.#sJ(J)}#LQ(){let J=({value:$,title:X,subtitle:Y,advanced:j=!1})=>f("fig-select-option",{value:$,label:`${X} — ${Y}`,className:j?"fig-fill-picker-gradient-interpolation-advanced":null},[f("fig-interpolation-swatch",{slot:"prepend",size:"large","aria-hidden":"true"}),f("span",{className:"fig-fill-picker-gradient-interpolation-label"},[f("span",{className:"fig-fill-picker-gradient-interpolation-title"},X),f("span",{className:"fig-fill-picker-gradient-interpolation-subtitle"},Y)])]),Q=f("fig-separator",{className:"fig-fill-picker-gradient-interpolation-advanced"}),Z=N.#j;return[...Z.filter(($)=>!$.advanced).map(J),Q,...Z.filter(($)=>$.advanced).map(J)]}#sJ(J){let Q=(L)=>typeof L.detail==="string"?L.detail:L.target?.value,Z=J.querySelector(".fig-fill-picker-gradient-bar-input"),$=(L)=>{if(!Z)return;this.#V=!0;try{Z.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(L)}))}finally{this.#V=!1}},X=()=>{$(this.#Q)};J.querySelector(".fig-fill-picker-gradient-type")?.addEventListener("change",(L)=>{let q=Q(L);if(!q)return;this.#Q.type=q,this.#P(),this.#O()});let j=J.querySelector(".fig-fill-picker-gradient-space"),K=j?.querySelector("fig-select-options"),U="fig-fill-picker-gradient-interpolation-collapsed",z=K?.querySelector(".fig-fill-picker-gradient-interpolation-advanced"),G=()=>Boolean(K?.classList.contains(U)),W=(L)=>{K?.querySelector(".fig-overflow-end")?.setAttribute("aria-label",L?"Show all color interpolation options":"Scroll down")},O=()=>{if(!K)return;K.classList.remove(U),K.style.removeProperty("max-height"),W(!1),K.syncOverflow?.()},V=()=>{if(!K||!z)return;K.style.removeProperty("max-height"),K.classList.add(U),K.scrollTop=0;let L=K.getBoundingClientRect().top,q=z.getBoundingClientRect().top,M=K.querySelector(".fig-overflow-end")?.offsetHeight||0,F=q-L;if(F>0)K.style.maxHeight=`${Math.round(F+M)}px`;W(!0),K.syncOverflow?.()},H=(L)=>Boolean(K?.querySelector(`fig-select-option.fig-fill-picker-gradient-interpolation-advanced[value="${L}"]`)),R=()=>{if(H(v(this.#Q)))O();else V()};if(K?.addEventListener("click",(L)=>{if(!G())return;if(!L.target?.closest?.(".fig-overflow-end"))return;L.preventDefault(),L.stopPropagation(),O()},!0),K?.addEventListener("focusin",(L)=>{if(!G())return;if(L.target?.closest?.(".fig-fill-picker-gradient-interpolation-advanced"))O()}),K?.addEventListener("scroll",()=>{if(G()&&K.scrollTop!==0)K.scrollTop=0}),j?.querySelectorAll("fig-select-option").forEach((L)=>{let q=()=>{let M=D(L.getAttribute("value")||"srgb");$(y({...this.#Q,...M}))};L.addEventListener("pointerenter",q),L.addEventListener("pointerleave",()=>{if(document.activeElement!==L)X()}),L.addEventListener("focus",q),L.addEventListener("blur",()=>{if(!L.matches(":hover"))X()})}),this.#A?.disconnect(),j)this.#A=new MutationObserver(()=>{if(!j.hasAttribute("open"))X();else this.#y(R)}),this.#A.observe(j,{attributes:!0,attributeFilter:["open"]});let _=J.querySelector(".fig-fill-picker-gradient-interpolation-modes");if(_?.addEventListener("change",(L)=>{let q=typeof L.detail==="string"?L.detail:L.target?.value;if(!q)return;let M=D(q);this.#Q=y({...this.#Q,...M}),this.#P(),this.#O()}),_?.querySelectorAll("fig-segment").forEach((L)=>{let q=()=>{$(y({...this.#Q,...D(L.getAttribute("value")||"srgb")}))};L.addEventListener("pointerenter",q),L.addEventListener("pointerleave",X)}),j?.addEventListener("change",(L)=>{let q=Q(L);if(!q)return;let M=D(q);this.#Q=y({...this.#Q,...M}),this.#P(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-rotate")?.addEventListener("click",()=>{this.#Q.angle=(Number(this.#Q.angle)+90)%360,this.#P(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#Q.stops.forEach((L)=>{L.position=100-L.position}),this.#Q.stops.sort((L,q)=>L.position-q.position),this.#P(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#Q.stops.push({position:50,color:"#888888",opacity:100}),this.#Q.stops.sort((q,M)=>q.position-M.position),this.#P(),this.#O()}),Z){let L=(q)=>{if(q.stopPropagation(),this.#V)return;let M=q.detail;if(!M?.gradient)return;this.#Q=S({...this.#Q,...M.gradient}),this.#L(),this.#WJ(),this.#IJ()};Z.addEventListener("input",(q)=>{L(q),this.#O()}),Z.addEventListener("change",(q)=>{L(q),this.#S()})}J.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(L)=>{this.#oJ(L)})}#NJ(J){let Q=String(J.color||"#888888").replace(/^#/,"").slice(0,6),Z=J.opacity??100;if(Z>=100)return`#${Q}`;let $=Math.round(Z/100*255).toString(16).padStart(2,"0");return`#${Q}${$}`}#iJ(J){if(!(J instanceof HTMLElement))return"#888888";if(J.hexOpaque)return this.#FJ(J.hexOpaque);let Q=J.value;if(typeof Q==="string"&&Q.startsWith("#"))return this.#FJ(Q.length>7?Q.slice(0,7):Q);let Z=J.querySelector('fig-input-text:not([type="number"])'),$=String(Z?.value??Z?.getAttribute("value")??"").replace(/#/g,"").slice(0,6);if(/^[0-9A-Fa-f]{6}$/.test($))return`#${$.toUpperCase()}`;let X=J.getAttribute("value");if(typeof X==="string"&&X.startsWith("#"))return this.#FJ(X.length>7?X.slice(0,7):X);return"#888888"}#FJ(J){let Q=String(J||"#888888").replace(/^#/,"").slice(0,6);if(!/^[0-9A-Fa-f]{6}$/.test(Q))return"#888888";return`#${Q.toUpperCase()}`}#rJ(J){let Q=J.querySelector(".fig-fill-picker-stop-position"),Z=J.querySelector(".fig-fill-picker-stop-color"),$=parseFloat(Q?.value??Q?.getAttribute("value")??"0")||0,X=this.#iJ(Z),Y=100;if(Z instanceof HTMLElement&&Z.rgba?.a!==void 0)Y=Math.round(Z.rgba.a*100);else{let j=parseInt(J.dataset.index,10);if(!isNaN(j)&&this.#Q.stops[j])Y=this.#Q.stops[j].opacity??100}return{position:$,color:X,opacity:Y}}#DJ(J){let Q=parseInt(J.dataset.index,10);if(isNaN(Q)||Q<0||Q>=this.#Q.stops.length)return;let Z={...this.#Q.stops[Q],...this.#rJ(J)};this.#Q.stops[Q]=Z,this.#lJ(J,Z)}#lJ(J,Q){let Z=J.querySelector(".fig-fill-picker-stop-position");if(Z)Z.setAttribute("value",String(Q.position));let $=J.querySelector(".fig-fill-picker-stop-color");if($)$.setAttribute("value",this.#NJ(Q))}#oJ(J){let{oldIndex:Q,newIndex:Z}=J.detail??{};if(Q==null||Z==null||Q===Z||Q<0||Z<0||Q>=this.#Q.stops.length||Z>=this.#Q.stops.length)return;let X=J.currentTarget.querySelectorAll(".fig-fill-picker-gradient-stop-row");X.forEach((j)=>this.#DJ(j));let[Y]=this.#Q.stops.splice(Q,1);this.#Q.stops.splice(Z,0,Y),X.forEach((j,K)=>{j.dataset.index=String(K)}),this.#V=!0;try{this.#WJ(),this.#UJ(),this.#O()}finally{this.#V=!1}}#P(){if(!this.#J)return;let J=this.#J.querySelector('[data-tab="gradient"]');if(!J)return;this.#Q=S(this.#Q);let Q=v(this.#Q),Z=J.querySelector(".fig-fill-picker-gradient-space");if(Z)Z.value=Q;let $=J.querySelector(".fig-fill-picker-gradient-interpolation-modes");if($){let X=N.#Y(Q),Y=$.querySelector(`fig-segment[value="${Q}"]`)||$.querySelector(`fig-segment[data-space="${X.space}"]`);if(Y){let j=`${X.title} — ${X.subtitle}`;Y.setAttribute("value",Q),Y.setAttribute("aria-label",j);let K=Y.closest("fig-tooltip");if(K)K.setAttribute("text",j);$.value=Q}}this.#WJ(),this.#UJ(),this.#IJ()}#nJ(){let J=Array.isArray(this.#Q.stops)?[...this.#Q.stops].sort((Q,Z)=>(Q.position??0)-(Z.position??0)):[];if(J.length<2)return[{color:"#FF0000",position:0},{color:"#4F9EFF",position:100}];return J.map((Q)=>({color:String(Q.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:Q.position??0}))}#WJ(){if(!this.#J)return;let J=this.#nJ();this.#J.querySelectorAll("fig-interpolation-swatch").forEach((Q)=>{let Z=Q.closest("fig-select-option, fig-segment")?.getAttribute("value")||"srgb",$=D(Z),X={type:"linear",stops:J,interpolationSpace:$.interpolationSpace};if(E.has($.interpolationSpace))X.hueInterpolation=$.hueInterpolation;Q.value={type:"gradient",gradient:X}})}#UJ(){if(!this.#J)return;let J=this.#J.querySelector(".fig-fill-picker-gradient-bar-input");if(J)this.#V=!0,J.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(this.#Q)})),this.#V=!1;this.#L()}#IJ(){if(!this.#J)return;let J=this.#J.querySelector(".fig-fill-picker-gradient-stops-list"),Q=J?.querySelector("fig-reorder");if(!J||!Q)return;let Z=Q.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(Z.length===this.#Q.stops.length){this.#Q.stops.forEach(($,X)=>{let Y=Z[X];Y.dataset.index=X;let j=Y.querySelector(".fig-fill-picker-stop-position");if(j)j.setAttribute("value",$.position);let K=Y.querySelector(".fig-fill-picker-stop-color");if(K)K.setAttribute("value",this.#NJ($));let U=Y.querySelector(".fig-fill-picker-stop-remove");if(U)if(this.#Q.stops.length<=2)U.setAttribute("disabled","");else U.removeAttribute("disabled")});return}this.#aJ(J)}#aJ(J){let Q=J.querySelector("fig-reorder");if(!Q)return;let Z=this.#Q.stops.map(($,X)=>f("fig-field",{className:"fig-fill-picker-gradient-stop-row","data-index":X},[f("fig-input-number",{className:"fig-fill-picker-stop-position","aria-label":"Gradient stop position",min:"0",max:"100",value:$.position,units:"%"}),f("fig-input-color",{className:"fig-fill-picker-stop-color","aria-label":"Gradient stop color",text:"true",alpha:"true",picker:"figma","picker-dialog-position":"right",value:this.#NJ($)}),f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-stop-remove",disabled:this.#Q.stops.length<=2,"aria-label":"Remove gradient stop"},C("minus"))]));Q.replaceChildren(...Z),Q.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach(($)=>{$.querySelector(".fig-fill-picker-stop-position").addEventListener("input",()=>{this.#DJ($),this.#WJ(),this.#UJ(),this.#O()});let X=$.querySelector(".fig-fill-picker-stop-color"),Y=X.querySelector("fig-fill-picker");if(Y)Y.anchorElement=this.#J;else this.#y(()=>{let K=X.querySelector("fig-fill-picker");if(K)K.anchorElement=this.#J});let j=()=>{this.#DJ($),this.#V=!0;try{this.#WJ(),this.#UJ(),this.#O()}finally{this.#V=!1}};X.addEventListener("input",j),X.addEventListener("change",j),$.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{let K=parseInt($.dataset.index,10);if(this.#Q.stops.length>2)this.#Q.stops.splice(K,1),this.#P(),this.#O()})})}#CJ(J,Q=!0){let Z=y({...this.#Q,interpolationSpace:J??this.#Q.interpolationSpace}),$=this.#k==="display-p3",X=Z.stops.map((K)=>{let U=(K.opacity??100)/100;return`${$?this.#WQ(K.color,U):this.#XQ(K.color,U)} ${K.position}%`}).join(", "),Y=$J(Z),j=Q&&Y?` ${Y}`:"";switch(Z.type){case"linear":return`linear-gradient(${Z.angle}deg${j}, ${X})`;case"radial":return`radial-gradient(circle at ${Z.centerX}% ${Z.centerY}%${j}, ${X})`;case"angular":return`conic-gradient(from ${Z.angle}deg${j}, ${X})`;default:return`linear-gradient(${Z.angle}deg${j}, ${X})`}}static#xJ=new Map;#wJ(J){let Q=N.#xJ.get(J);if(Q!==void 0)return Q;let Z=document.createElement("div");Z.style.background=J;let $=!!Z.style.background;return N.#xJ.set(J,$),$}#uJ(){let J=this.#CJ(void 0,!0);if(this.#wJ(J))return J;let Q=this.#CJ("oklab",!0);if(this.#wJ(Q))return Q;return this.#CJ("oklab",!1)}#tJ(){let J=this.#J.querySelector('[data-tab="image"]'),Q=f("fig-select",{className:"fig-fill-picker-scale-mode",label:"Image scale mode",value:this.#z.scaleMode},f("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"],["tile","Tile"]].map(([Y,j])=>f("fig-select-option",{value:Y},j)))),Z=f("fig-input-number",{className:"fig-fill-picker-scale","aria-label":"Image tile scale",min:"1",max:"200",value:this.#z.scale,units:"%"});if(this.#z.scaleMode!=="tile")Z.style.display="none";let $=f("fig-field",{className:"fig-fill-picker-media-header"},[Q,Z]),X=f("fig-image",{className:"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"});J.replaceChildren($,X),this.#eJ(J)}#eJ(J){let Q=J.querySelector(".fig-fill-picker-scale-mode"),Z=J.querySelector(".fig-fill-picker-scale"),$=J.querySelector(".fig-fill-picker-image-preview");Q.addEventListener("change",(X)=>{let Y=typeof X.detail==="string"?X.detail:X.target?.value;if(!Y)return;this.#z.scaleMode=Y,Z.style.display=Y==="tile"?"block":"none",this.#r($),this.#L(),this.#O()}),Z.addEventListener("input",(X)=>{this.#z.scale=parseFloat(X.target.value)||100,this.#r($),this.#L(),this.#O()}),$.addEventListener("loaded",(X)=>{let Y=X.detail?.src||$.src;if(!Y)return;this.#z.url=Y,this.#r($),this.#L(),this.#O()}),$.addEventListener("change",()=>{if($.src)return;this.#z.url=null,this.#r($),this.#L(),this.#O()}),this.#r($)}#r(J){if(!this.#z.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.#z.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.#z.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.#z.url})`,J.style.backgroundPosition="top left",J.style.backgroundSize=`${this.#z.scale}%`,J.style.backgroundRepeat="repeat",J.mediaEl)J.mediaEl.style.opacity="0";break}}#ZJ(J){if(J.tagName==="FIG-MEDIA"){if(!this.#X.url){J.removeAttribute("src"),J.classList.remove("has-media");return}if(J.setAttribute("src",this.#X.url),this.#X.poster)J.setAttribute("poster",this.#X.poster);else J.removeAttribute("poster");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.#X.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.#X.scaleMode){case"fill":case"crop":J.style.objectFit="cover";break;case"fit":J.style.objectFit="contain";break}}#JQ(){let J=this.#J.querySelector('[data-tab="video"]'),Q=f("fig-select",{className:"fig-fill-picker-scale-mode",label:"Video scale mode",value:this.#X.scaleMode},f("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"]].map(([X,Y])=>f("fig-select-option",{value:X},Y)))),Z=f("fig-field",{className:"fig-fill-picker-media-header"},Q),$=f("fig-media",{className:"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:!0,muted:"true",loop:"true"});J.replaceChildren(Z,$),this.#QQ(J),this.#qJ()}#bJ(){if(this.#X.poster?.startsWith("blob:"))URL.revokeObjectURL(this.#X.poster),this.#u.delete(this.#X.poster);this.#X.poster=null}#qJ({emit:J=!0}={}){if(this.#X.url){if(this.#X.missing=!1,!this.#X.poster)this.#EJ(this.#X.url,{emit:J});return}let Q=this.getAttribute("default-video");if(!Q){this.#X.missing=!0;return}this.#X.url=Q,this.#X.missing=!1;let Z=this.#J?.querySelector(".fig-fill-picker-video-preview");if(Z)this.#ZJ(Z);this.#EJ(Q,{emit:J})}async#EJ(J,{emit:Q=!0}={}){if(!J)return;let Z=document.createElement("video");Z.muted=!0,Z.playsInline=!0,Z.preload="auto",Z.crossOrigin="anonymous";try{if(await new Promise((Y,j)=>{let K=()=>j(Error("video poster failed"));Z.addEventListener("error",K,{once:!0}),Z.addEventListener("loadeddata",Y,{once:!0}),Z.src=J}),!Z.videoWidth||!Z.videoHeight)return;let $=document.createElement("canvas");$.width=Z.videoWidth,$.height=Z.videoHeight,$.getContext("2d").drawImage(Z,0,0);let X=await new Promise((Y)=>$.toBlob(Y,"image/jpeg",0.85));if(!X)return;if(this.#bJ(),this.#X.poster=URL.createObjectURL(X),this.#u.add(this.#X.poster),this.#L(),Q)this.#O()}catch{}}#QQ(J){let Q=J.querySelector(".fig-fill-picker-scale-mode"),Z=J.querySelector(".fig-fill-picker-video-preview");Q.addEventListener("change",($)=>{let X=typeof $.detail==="string"?$.detail:$.target?.value;if(!X)return;this.#X.scaleMode=X,this.#ZJ(Z),this.#L(),this.#O()}),Z.addEventListener("loaded",($)=>{let X=$.detail?.src||Z.src;if(!X)return;this.#X.url=X,this.#X.missing=!1,this.#ZJ(Z),Z.play?.(),this.#EJ(X),this.#L(),this.#O()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#X.url=null,this.#bJ(),this.#qJ(),this.#ZJ(Z),this.#L(),this.#O()}),this.#ZJ(Z)}#ZQ(){let J=this.#J.querySelector('[data-tab="webcam"]'),Q=f("fig-field",{className:"fig-fill-picker-webcam-camera"},f("fig-select",{className:"fig-fill-picker-camera-select",label:"Camera",full:!0},document.createElement("fig-select-options")));Q.style.display="none";let Z=f("video",{className:"fig-fill-picker-webcam-video",autoplay:!0,muted:!0,playsinline:!0});Z.muted=!0;let $=f("div",{className:"fig-fill-picker-webcam-status",role:"status","aria-live":"polite"},f("span",{},"Camera access required")),X=f("fig-video",{className:"fig-fill-picker-webcam-preview","aria-label":"Webcam preview","aspect-ratio":"1/1",fit:"cover",checkerboard:"true",autoplay:"true",muted:"true"},[Z,$]),Y=f("div",{className:"fig-fill-picker-webcam-controls"},f("fig-button",{className:"fig-fill-picker-webcam-capture",variant:"secondary",full:!0,disabled:!0},"Capture"));J.replaceChildren(Q,X,Y),this.#$Q(J)}#$Q(J){let Q=J.querySelector(".fig-fill-picker-webcam-video"),Z=J.querySelector(".fig-fill-picker-webcam-status"),$=J.querySelector(".fig-fill-picker-webcam-capture"),X=J.querySelector(".fig-fill-picker-webcam-camera"),Y=J.querySelector(".fig-fill-picker-camera-select"),j=(W)=>{if(W)$.removeAttribute("disabled");else $.setAttribute("disabled","")},K=()=>{let W=!!this.#$.stream&&Q.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&Q.videoWidth>0&&Q.videoHeight>0;if(j(W),W)Z.querySelector("span").textContent="Camera ready",Z.style.display="none",this.#D(Q)};Q.addEventListener("loadedmetadata",K),Q.addEventListener("canplay",K);let U=(W)=>{this.#$.stream=W,Q.srcObject=W,Q.style.display="block",K()},z=async(W,O)=>{let V=await navigator.mediaDevices.enumerateDevices();if(W!=null&&W!==this.#w)return;let H=V.filter((R)=>R.kind==="videoinput");if(H.length>1){X.style.display="";let R=Y.querySelector(":scope > fig-select-options");if(!R)R=document.createElement("fig-select-options"),Y.append(R);if(R.replaceChildren(),H.forEach((_,T)=>{let L=document.createElement("fig-select-option");L.value=_.deviceId;let q=_.label||(H.length>1?`Camera ${T+1}`:"Camera");L.textContent=q.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(M,F)=>{return` ${/^\d+$/.test(F)?Number.parseInt(F,10).toString():F.replace(/^0+/,"")||"0"}`}),R.append(L)}),O)Y.value=O}else X.style.display="none",Y.querySelector(":scope > fig-select-options")?.replaceChildren()},G=async(W=null)=>{let O=W||this.#$.deviceId||null,V=this.#$.stream,H=V?.getTracks?.().filter((_)=>_.readyState!=="ended")??[];if(V&&H.length){let _=V.getVideoTracks?.()?.[0]?.getSettings?.()?.deviceId||this.#$.deviceId||null;if(!O||O===_){U(V),this.#jJ(),z(null,O||_);return}}this.#N({emit:Boolean(V)});let R=this.#w;j(!1),Z.querySelector("span").textContent="Starting camera",Z.style.display="flex";try{let _={video:O?{deviceId:{exact:O}}:!0},T=await navigator.mediaDevices.getUserMedia(_);if(R!==this.#w||!this.isConnected||this.#q!=="webcam"){T.getTracks().forEach((q)=>q.stop());return}let L=T.getVideoTracks?.()?.[0];this.#$.deviceId=O||L?.getSettings?.()?.deviceId||null,this.#$.live=this.#n()==="live",U(T),this.#jJ(),await z(R,O)}catch(_){if(R!==this.#w)return;console.error("Webcam error:",_.name,_.message);let T="Camera access denied";if(_.name==="NotAllowedError")T="Camera permission denied";else if(_.name==="NotFoundError")T="No camera found";else if(_.name==="NotReadableError")T="Camera in use by another app";else if(_.name==="OverconstrainedError")T="Camera constraints not supported";else if(!window.isSecureContext)T="Camera requires secure context";Z.replaceChildren();let L=document.createElement("span");L.textContent=T,Z.appendChild(L),Z.style.display="flex",Q.style.display="none",j(!1)}};this.#l=G,Y.addEventListener("change",(W)=>{let O=typeof W.detail==="string"?W.detail:W.target?.value;if(!O||O===this.#$.deviceId)return;G(O)}),$.addEventListener("click",async()=>{if(!this.#$.stream)return;let W=await this.#v(Q);if(!W)return;this.#z.url=W,this.#$.live=!1;let O=this.#J.querySelector(".fig-fill-picker-image-preview");if(O)this.#r(O);if(Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).some((H)=>H.dataset.tab==="image"))this.#s("image");else this.#L(),this.#O();this.#S()})}#AJ(J){let Q=J.h/360,Z=J.s/100,$=J.v/100,X,Y,j,K=Math.floor(Q*6),U=Q*6-K,z=$*(1-Z),G=$*(1-U*Z),W=$*(1-(1-U)*Z);switch(K%6){case 0:X=$,Y=W,j=z;break;case 1:X=G,Y=$,j=z;break;case 2:X=z,Y=$,j=W;break;case 3:X=z,Y=G,j=$;break;case 4:X=W,Y=z,j=$;break;case 5:X=$,Y=z,j=G;break}return{r:Math.round(X*255),g:Math.round(Y*255),b:Math.round(j*255)}}#$J(J){let Q=J.r/255,Z=J.g/255,$=J.b/255,X=Math.max(Q,Z,$),Y=Math.min(Q,Z,$),j=X-Y,K=0,U=X===0?0:j/X,z=X;if(X!==Y){switch(X){case Q:K=(Z-$)/j+(Z<$?6:0);break;case Z:K=($-Q)/j+2;break;case $:K=(Q-Z)/j+4;break}K/=6}return{h:K*360,s:U*100,v:z*100,a:1}}#m(J){if(!J||typeof J.h!=="number"||typeof J.s!=="number"||typeof J.v!=="number")return"#D9D9D9";let Q=this.#AJ(J),Z=($)=>{return(isNaN($)?217:Math.max(0,Math.min(255,Math.round($)))).toString(16).padStart(2,"0")};return`#${Z(Q.r)}${Z(Q.g)}${Z(Q.b)}`}#XJ(J){let Q=parseInt(J.slice(1,3),16),Z=parseInt(J.slice(3,5),16),$=parseInt(J.slice(5,7),16);return this.#$J({r:Q,g:Z,b:$})}#XQ(J,Q=1){let Z=parseInt(J.slice(1,3),16),$=parseInt(J.slice(3,5),16),X=parseInt(J.slice(5,7),16);return`rgba(${Z}, ${$}, ${X}, ${Q})`}#YQ(J){let Q=Math.max(0,Math.min(1,Number(J)||0)),Z=Math.round(Q*1000)/1000;return String(Z)}#jQ(J=this.#Z){let Q=this.#AJ(J);return`rgba(${Q.r}, ${Q.g}, ${Q.b}, ${this.#YQ(J.a)})`}#KQ(J){let Q=String(J??"").trim();if(!Q)return null;let Z=Q.match(/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(Z){let X=Z[1];if(X.length===3)X=X[0]+X[0]+X[1]+X[1]+X[2]+X[2];let Y=1;if(X.length===8)Y=parseInt(X.slice(6,8),16)/255,X=X.slice(0,6);return{...this.#XJ(`#${X}`),a:Y}}let $=Q.match(/^rgba?\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))(?:\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*)?\)$/i);if($){let X=Math.max(0,Math.min(255,Math.round(parseFloat($[1])))),Y=Math.max(0,Math.min(255,Math.round(parseFloat($[2])))),j=Math.max(0,Math.min(255,Math.round(parseFloat($[3])))),K=$[4]!==void 0?Math.max(0,Math.min(1,parseFloat($[4]))):1;if(![X,Y,j,K].every(Number.isFinite))return null;return{...this.#$J({r:X,g:Y,b:j}),a:K}}return null}#WQ(J,Q=1){let Z=+(parseInt(J.slice(1,3),16)/255).toFixed(4),$=+(parseInt(J.slice(3,5),16)/255).toFixed(4),X=+(parseInt(J.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${Z} ${$} ${X} / ${Q})`}#UQ(J){let Q=J.r/255,Z=J.g/255,$=J.b/255,X=Math.max(Q,Z,$),Y=Math.min(Q,Z,$),j,K,U=(X+Y)/2;if(X===Y)j=K=0;else{let z=X-Y;switch(K=U>0.5?z/(2-X-Y):z/(X+Y),X){case Q:j=((Z-$)/z+(Z<$?6:0))/6;break;case Z:j=(($-Q)/z+2)/6;break;case $:j=((Q-Z)/z+4)/6;break}}return{h:j*360,s:K*100,l:U*100}}#zQ(J){let Q=J.h/360,Z=J.s/100,$=J.l/100,X,Y,j;if(Z===0)X=Y=j=$;else{let K=(G,W,O)=>{if(O<0)O+=1;if(O>1)O-=1;if(O<0.16666666666666666)return G+(W-G)*6*O;if(O<0.5)return W;if(O<0.6666666666666666)return G+(W-G)*(0.6666666666666666-O)*6;return G},U=$<0.5?$*(1+Z):$+Z-$*Z,z=2*$-U;X=K(z,U,Q+0.3333333333333333),Y=K(z,U,Q),j=K(z,U,Q-0.3333333333333333)}return{r:Math.round(X*255),g:Math.round(Y*255),b:Math.round(j*255)}}#vJ(J){let Q=(W)=>{return W=W/255,W<=0.04045?W/12.92:Math.pow((W+0.055)/1.055,2.4)},Z=Q(J.r),$=Q(J.g),X=Q(J.b),Y=0.4122214708*Z+0.5363325363*$+0.0514459929*X,j=0.2119034982*Z+0.6806995451*$+0.1073969566*X,K=0.0883024619*Z+0.2817188376*$+0.6299787005*X,U=Math.cbrt(Y),z=Math.cbrt(j),G=Math.cbrt(K);return{l:0.2104542553*U+0.793617785*z-0.0040720468*G,a:1.9779984951*U-2.428592205*z+0.4505937099*G,b:0.0259040371*U+0.7827717662*z-0.808675766*G}}#OQ(J){let Q=this.#vJ(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}}#hJ(J){let Q=J.l+0.3963377774*J.a+0.2158037573*J.b,Z=J.l-0.1055613458*J.a-0.0638541728*J.b,$=J.l-0.0894841775*J.a-1.291485548*J.b,X=Q*Q*Q,Y=Z*Z*Z,j=$*$*$,K=(U)=>{let z=U<=0.0031308?12.92*U:1.055*Math.pow(U,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,z))*255)};return{r:K(4.0767416621*X-3.3077115913*Y+0.2309699292*j),g:K(-1.2684380046*X+2.6097574011*Y-0.3413193965*j),b:K(-0.0041960863*X-0.7034186147*Y+1.707614701*j)}}#fQ(J){let Q=J.h*Math.PI/180;return this.#hJ({l:J.l,a:J.c*Math.cos(Q),b:J.c*Math.sin(Q)})}#O(){if(this.#b())return;this.#L(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#S(){if(this.#b())return;this.#x=JSON.stringify(this.value),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let J={type:this.#U,colorSpace:this.#k};switch(this.#U){case"solid":return{...J,color:this.#m(this.#Z),alpha:this.#Z.a,hsv:{...this.#Z}};case"gradient":return{...J,gradient:P(this.#Q),css:this.#uJ()};case"image":return{...J,image:{...this.#z}};case"video":return{...J,video:this.#HJ()};case"webcam":return{...J,webcam:this.#zJ()};default:return{...J,...this.#F[this.#U]}}}set value(J){if(typeof J==="string")this.setAttribute("value",J);else this.setAttribute("value",JSON.stringify(J))}attributeChangedCallback(J,Q,Z){if(Q===Z)return;switch(J){case"value":if(this.#GJ(),this.#L(),this.#J?.open&&!this.#M)this.#TJ(),this.#x=JSON.stringify(this.value);break;case"disabled":if(this.#E(),this.#b()&&this.#J?.open)this.close();break;case"alpha":case"mode":{if(!this.#J)break;let $=this.#J.open;if(this.#e(),$&&this.isConnected)this.#t();break}case"webcam-mode":if(this.#U==="webcam")this.#L();break;case"default-video":if(this.#U==="video")this.#qJ({emit:!1}),this.#L();break;case"aria-label":if(this.#J)this.#J.setAttribute("aria-label",this.#a());case"aria-labelledby":case"aria-describedby":this.#E();break}}}A("fig-fill-picker",N);class B extends HTMLElement{static#j=new Set(["oklch","hsl"]);static#Y=10;static#K=10;static#W=8;static#J=3;static#R=210;static#q={type:"linear",angle:135,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{color:"#FF0000",position:0,opacity:100},{color:"#4F9EFF",position:100,opacity:100}]};#U=!1;#k=null;#Z=null;#G={...B.#q};static get observedAttributes(){return["value"]}get value(){return{type:"gradient",gradient:{...this.#G}}}set value(J){if(J==null||J===""){this.removeAttribute("value");return}if(typeof J==="string"){this.setAttribute("value",J);return}this.setAttribute("value",JSON.stringify(J))}connectedCallback(){this.#Q(),this.#z(),this.#C(),this.#A()}attributeChangedCallback(J,Q,Z){if(Q===Z)return;if(J!=="value")return;if(this.#z(),this.#U)this.#A()}#Q(){if(!(this.hasAttribute("aria-label")||this.hasAttribute("aria-labelledby"))&&!this.hasAttribute("aria-hidden"))this.setAttribute("aria-hidden","true")}#z(){let J=this.getAttribute("value");if(!J){this.#G={...B.#q,stops:B.#q.stops.map((Q)=>({...Q}))};return}try{let Q=JSON.parse(J),Z=Q?.type==="gradient"&&Q.gradient?Q.gradient:Q?.gradient?Q.gradient:Q;if(!Z||typeof Z!=="object")return;this.#G=this.#X({...B.#q,...Z})}catch{}}#X(J){let Q={...J??{}},Z=String(Q.interpolationSpace??"srgb").toLowerCase(),$=String(Q.hueInterpolation??"shorter").toLowerCase(),X=Array.isArray(Q.stops)?Q.stops.map((Y)=>({color:String(Y?.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:Y?.position??0,opacity:Y?.opacity??100})):B.#q.stops.map((Y)=>({...Y}));if(X.length<2)return{...B.#q,stops:B.#q.stops.map((Y)=>({...Y}))};return{type:["linear","radial","angular"].includes(Q.type)?Q.type:"linear",angle:Number.isFinite(Number(Q.angle))?Number(Q.angle):135,interpolationSpace:Z,hueInterpolation:$,stops:X}}#$(){return B.#j.has(this.#G.interpolationSpace||"srgb")}#I(J){let{r:Q,g:Z,b:$}=i(J);if(this.#G.interpolationSpace==="hsl")return r(Q,Z,$).h;let X=l(Q,Z,$);return(o(X.l,X.a,X.b).h%360+360)%360}#_(){let J=this.#B(),Q=this.#I(J[0]?.color||"#FF0000"),Z=this.#I(J[J.length-1]?.color||"#4F9EFF"),$=B.#R-Q,Y=((B.#R-Z-$)%360+360)%360,j=Y===0?0:Y-360,K=this.#G.hueInterpolation||"shorter",U;if(K==="increasing")U=j;else if(K==="decreasing")U=Y;else if(K==="longer")U=Y<180?j:Y;else U=Y<=180?Y:j;let z=Math.sign(U),G=Math.asin(B.#J/2/B.#W)*180/Math.PI,W=Math.min(G,Math.max(0,(Math.abs(U)-0.01)/2));return{startDeg:$+z*W,sweepDeg:U-z*W*2}}#F(J){let Q=J*Math.PI/180;return{x:B.#Y+B.#W*Math.cos(Q),y:B.#K+B.#W*Math.sin(Q)}}#f(J,Q){let Z=J+Q,$=this.#F(J),X=this.#F(Z),Y=Math.abs(Q)>180?1:0,j=Q>=0?1:0;return`M ${$.x} ${$.y} A ${B.#W} ${B.#W} 0 ${Y} ${j} ${X.x} ${X.y}`}#H(){let J=this.#F(180),Q=this.#F(0);return`M ${J.x} ${J.y} L ${Q.x} ${Q.y}`}#T(J){let Q=B.#J,Z=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none"><path d="${J}" fill="none" stroke="white" stroke-width="${Q}" stroke-linecap="round" stroke-linejoin="round"/></svg>`;return`url("data:image/svg+xml,${encodeURIComponent(Z)}")`}#B(){return[...this.#G.stops].sort((J,Q)=>(J.position??0)-(Q.position??0))}#M(){let J=this.#G.interpolationSpace||"srgb";if(J==="srgb")return"";if(B.#j.has(J))return` in ${J} ${this.#G.hueInterpolation||"shorter"} hue`;return` in ${J}`}#V(){let J=this.#B(),Q=this.#M();if(this.#$()){let $=(B.#R+90)%360,X=this.#G.interpolationSpace,Y=(K)=>X==="oklch"?`oklch(65% 0.25 ${K})`:`hsl(${K} 100% 50%)`,j=[0,300,240,180,120,60,0].map(Y).join(", ");return`conic-gradient(from ${$}deg in ${X} decreasing hue, ${j})`}let Z=J.map(($)=>`${$.color} ${$.position??0}%`).join(", ");return`linear-gradient(90deg${Q}, ${Z})`}#C(){if(this.#U)return;let J=B.#J,Q=u("svg",{className:"fig-interpolation-swatch-svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true"},u("circle",{className:"fig-interpolation-swatch-rim",cx:"10",cy:"10",r:"8",fill:"none",stroke:"currentColor","stroke-width":J})),Z=f("div",{className:"fig-interpolation-swatch-fill","aria-hidden":"true"});this.replaceChildren(Q,Z),this.#k=Q,this.#Z=Z,this.#U=!0}#A(){if(!this.#Z)return;let J=this.#$();if(this.#k)this.#k.style.display=J?"":"none";let Q=J?(()=>{let{startDeg:$,sweepDeg:X}=this.#_();return this.#f($,X)})():this.#H(),Z=this.#T(Q);this.#Z.style.setProperty("-webkit-mask-image",Z),this.#Z.style.maskImage=Z,this.#Z.style.background=this.#V()}}A("fig-interpolation-swatch",B);
|
|
90
|
+
`,J.appendChild(Q);let Z=document.createElement("fig-button");Z.className="fig-select-trigger",Z.setAttribute("part","trigger"),Z.setAttribute("variant","ghost"),Z.setAttribute("aria-haspopup","listbox"),Z.setAttribute("aria-expanded","false");let $=document.createElement("span");$.className="fig-select-prepend",$.setAttribute("part","prepend"),$.setAttribute("aria-hidden","true");let X=document.createElement("span");X.className="fig-select-label",X.setAttribute("part","label"),Z.append($,X);let Y=document.createElement("dialog",{is:"fig-popup"});if(Y.setAttribute("is","fig-popup"),Y.setAttribute("part","listbox"),Y.setAttribute("theme","menu"),Y.setAttribute("role","listbox"),"popover"in HTMLElement.prototype)Y.setAttribute("popover","manual");Y.id=d(),Z.setAttribute("aria-controls",Y.id);let j=document.createElement("slot");if(j.setAttribute("name","panel"),Y.appendChild(j),J.append(Z,Y),this.#K=Z,this.#j=$,this.#W=X,this.#Y=Y,this.#J=j,Y.anchor=Z,this.#M(),this.#c(),!this.hasAttribute("value")){let K=this.#P().find((U)=>T(U,"selected"));if(K)this.setAttribute("value",K.value)}}#c(){if(!this.#Y||this.#$)return;if(typeof this.#Y.positionPopup!=="function")return;this.#L=this.#Y.positionPopup.bind(this.#Y),this.#Y.positionPopup=()=>{if(!this.open){this.#L?.();return}this.#p()},this.#$=!0}#E(J){if(!J)return null;let Q=document.createRange();Q.selectNodeContents(J);let Z=[...Q.getClientRects()].filter(($)=>$.width>0&&$.height>0);if(Z.length)return Z[0];return J.getBoundingClientRect()}#$J(){if(typeof this.#Y?.parseViewportMargins==="function")return this.#Y.parseViewportMargins();return{top:8,right:8,bottom:8,left:8}}#b(){let J=this.#W?.getBoundingClientRect();if(!J)return null;return{x:J.x,y:J.y,width:J.width,height:J.height}}#d(){let J=window.visualViewport;return{width:J?.width??window.innerWidth,height:J?.height??window.innerHeight,offsetLeft:J?.offsetLeft??0,offsetTop:J?.offsetTop??0}}#l(J,Q,Z=0.25){if(!J&&!Q)return!1;if(!J||!Q)return!0;return Math.abs(J.x-Q.x)>Z||Math.abs(J.y-Q.y)>Z||Math.abs(J.width-Q.width)>Z||Math.abs(J.height-Q.height)>Z}#o(J,Q,Z=0.25){if(!J&&!Q)return!1;if(!J||!Q)return!0;return Math.abs(J.width-Q.width)>Z||Math.abs(J.height-Q.height)>Z||Math.abs(J.offsetLeft-Q.offsetLeft)>Z||Math.abs(J.offsetTop-Q.offsetTop)>Z}#g(){if(!this.#Q)return!1;let J=this.#l(this.#z,this.#b()),Q=this.#o(this.#X,this.#d());return!J&&!Q}#A(){this.#z=this.#b(),this.#X=this.#d()}#p(){if(this.#g())return;let J=this.#Y,Q=this.#W;if(!J||!Q){this.#L?.();return}let Z=this.#P(),$=Z.find((R)=>this.#y(R)===this.value)||Z[0];if(!$){this.#L?.();return}this.#L?.();let X=J.getBoundingClientRect(),Y=Q.getBoundingClientRect(),j=this.#E($);if(!X.width||!X.height||!Y.width||!j)return;let K=j.left-X.left,U=j.top-X.top,L=T(this,"full")?this.getBoundingClientRect().left:Y.left-K,W=Y.top-U,O=this.#$J();if(typeof J.clampToViewport==="function")({left:L,top:W}=J.clampToViewport({left:L,top:W},X,O));else{let{left:R,top:_}=O,k=window.innerWidth-X.width-O.right,V=window.innerHeight-X.height-O.bottom;L=Math.min(Math.max(L,R),Math.max(R,k)),W=Math.min(Math.max(W,_),Math.max(_,V))}J.style.setProperty("right","auto","important"),J.style.setProperty("bottom","auto","important"),J.style.setProperty("left",`${Math.round(L)}px`,"important"),J.style.setProperty("top",`${Math.round(W)}px`,"important");let f=this.#f(),H=this.#E($);if(H&&f&&f.scrollHeight>f.clientHeight+1){let R=H.top-Y.top;if(Math.abs(R)>0.5)f.scrollTop+=R;f.syncOverflow?.()}if(this.#Q||this.open)this.#A()}#WJ(){this.#K?.addEventListener("click",this.#w),this.#K?.addEventListener("keydown",this.#V),this.addEventListener("click",this.#F),this.addEventListener("pointerover",this.#N),this.#Y?.addEventListener("keydown",this.#V),this.#Y?.addEventListener("close",this.#u),this.#J?.addEventListener("slotchange",this.#q)}#qJ(){this.#K?.removeEventListener("click",this.#w),this.#K?.removeEventListener("keydown",this.#V),this.removeEventListener("click",this.#F),this.removeEventListener("pointerover",this.#N),this.#Y?.removeEventListener("keydown",this.#V),this.#Y?.removeEventListener("close",this.#u),this.#J?.removeEventListener("slotchange",this.#q)}#HJ(){this.#M(),this.#B()}#BJ(){if(this.#_)return;this.#_=new MutationObserver((J)=>{if(this.#k||this.#Z)return;let Q=!1;for(let Z of J){if(Z.type==="childList"){if([...Z.addedNodes].some(($)=>this.#H($))||[...Z.removedNodes].some(($)=>this.#H($))||Z.target?.closest?.("fig-select-option"))Q=!0}if(Z.type==="attributes"&&Z.target?.tagName==="FIG-SELECT-OPTION"){if(Z.attributeName==="value"||Z.attributeName==="disabled"||Z.attributeName==="label")Q=!0;else if(Z.attributeName==="selected"){if(T(Z.target,"selected")){let $=this.#y(Z.target);if((this.getAttribute("value")??"")!==$)this.setAttribute("value",$),Q=!0}else if(this.#y(Z.target)===(this.getAttribute("value")??""))Q=!0}}if(Z.type==="characterData"&&Z.target?.parentElement?.tagName==="FIG-SELECT-OPTION")Q=!0}if(Q)this.#B()}),this.#_.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","disabled","selected","label"]})}#P({enabledOnly:J=!1}={}){let Q=this.#f(),Z=Q?Array.from(Q.querySelectorAll(":scope > fig-select-option")):[];if(!J)return Z;return Z.filter(($)=>!T($,"disabled"))}#y(J){if(!J)return"";if(typeof J.value==="string")return J.value;let Q=J.getAttribute?.("value");if(Q!=null)return Q;return(J.textContent||"").trim()}#RJ(J){if(!J)return"";let Q=J.getAttribute?.("label");if(Q!=null&&Q!=="")return Q.trim();let Z=[];for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE){let j=$.textContent?.trim();if(j)Z.push(j);continue}if(!($ instanceof Element))continue;let X=$.getAttribute("slot");if(X==="prepend"||X==="append")continue;let Y=$.textContent?.trim();if(Y)Z.push(Y)}if(Z.length)return Z.join(" ").trim();return(J.textContent||"").trim()}#_J(J){if(!this.#j)return;let Q=J?.querySelector?.(':scope > [slot="prepend"]');this.#j.replaceChildren(...Array.from(Q?.childNodes??[],(Z)=>Z.cloneNode(!0)))}#UJ(){if(!this.#Y)return;this.#Y.setAttribute("position",this.getAttribute("position")||"bottom left");let J=this.getAttribute("offset");if(J)this.#Y.setAttribute("offset",J);else this.#Y.removeAttribute("offset");let Q=this.getAttribute("closedby");if(Q)this.#Y.setAttribute("closedby",Q);else this.#Y.removeAttribute("closedby")}#zJ(){let J=T(this,"disabled");if(this.#K)if(J)this.#K.setAttribute("disabled","");else this.#K.removeAttribute("disabled");if(J&&this.open)this.open=!1}#OJ(J){if(!J.length)return null;let Q=J.find((Z)=>T(Z,"selected"));if(Q&&!T(Q,"disabled"))return Q;return J.find((Z)=>!T(Z,"disabled"))||J[0]||null}#GJ(J){this.dispatchEvent(new CustomEvent("input",{detail:J,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:J,bubbles:!0,composed:!0}))}#B(){if(this.#k)return;this.#k=!0;try{let J=this.#P(),Q=this.hasAttribute("value"),Z=Q?this.getAttribute("value"):null,$=Q?J.find((K)=>this.#y(K)===Z):null,X=!1;if(!$){if(Q){if(!J.length){if(this.#W)this.#W.textContent=Z||this.getAttribute("label")||"";return}if($=this.#OJ(J),$){let K=this.#y($);if(Z!==K)this.setAttribute("value",K),X=!0}else this.removeAttribute("value"),X=!0}else if($=J.find((K)=>T(K,"selected")),$)this.setAttribute("value",this.#y($)),X=!0}for(let K of J){let U=K===$;if(K.setAttribute("aria-selected",U?"true":"false"),U)K.setAttribute("selected","");else K.removeAttribute("selected")}let Y=$&&this.#RJ($)||this.getAttribute("label")||"";if(this.#W)this.#W.textContent=Y;this.#_J($);let j=this.getAttribute("label")||"Select";if(this.#K?.setAttribute("aria-label",j),this.#f()?.syncOverflow?.(),X)this.#GJ(this.getAttribute("value")??"")}finally{this.#k=!1}}#TJ(J){if(T(this,"disabled"))return;J.preventDefault(),J.stopPropagation();let Q=!this.open;if(Q&&this.#Y&&this.#K)this.#Y.anchor=this.#K;this.open=Q}#kJ(J){let Z=(typeof J.composedPath==="function"?J.composedPath():[]).find(($)=>$?.tagName==="FIG-SELECT-OPTION");if(!Z||!this.contains(Z))return;if(T(Z,"disabled"))return;this.#LJ(Z)}#MJ(J){let Z=(typeof J.composedPath==="function"?J.composedPath():[]).find(($)=>$?.tagName==="FIG-SELECT-OPTION");if(!Z||!this.contains(Z))return;if(T(Z,"disabled"))return;if(J.relatedTarget instanceof Node&&Z.contains(J.relatedTarget))return;this.dispatchEvent(new CustomEvent("optionhover",{detail:this.#y(Z),bubbles:!0,composed:!0}))}#n(J){if(J.currentTarget===document&&J.key!=="Escape")return;if(!(this.open&&(this.#Y?.matches?.(":open")??!1))){if(this.#K?.contains(J.target)&&(J.key==="ArrowDown"||J.key==="Enter"||J.key===" ")){if(J.preventDefault(),this.#Y&&this.#K)this.#Y.anchor=this.#K;this.open=!0,requestAnimationFrame(()=>{let X=this.#P({enabledOnly:!0}).findIndex((Y)=>this.#y(Y)===this.value);this.#G(X>=0?X:0)})}return}let Z=this.#P({enabledOnly:!0});if(!Z.length)return;switch(J.key){case"ArrowDown":J.preventDefault(),this.#a(),this.#G(this.#U+1);break;case"ArrowUp":J.preventDefault(),this.#a(),this.#G(this.#U-1);break;case"Home":J.preventDefault(),this.#G(0);break;case"End":J.preventDefault(),this.#G(Z.length-1);break;case"Escape":J.preventDefault(),this.open=!1,this.#K?.focus();break;case"Enter":case" ":{this.#a();let $=Z[this.#U];if(!$)return;J.preventDefault(),this.#LJ($);break}}}#S(){if(this.hasAttribute("open"))this.removeAttribute("open");this.#K?.setAttribute("aria-expanded","false"),this.#K?.focus(),this.#U=-1}#LJ(J){let Q=this.#y(J);this.setAttribute("value",Q),this.#B(),this.#GJ(Q),this.open=!1}#XJ(){return this.#P({enabledOnly:!0})}#a(){let J=this.#XJ();if(!J.length){this.#U=-1;return}let Q=J.find(($)=>$===document.activeElement),Z=Q?J.indexOf(Q):-1;this.#U=Z>=0?Z:this.#U}#G(J){let Q=this.#XJ();if(!Q.length)return;let Z=(J%Q.length+Q.length)%Q.length;this.#U=Z,Q[Z]?.focus()}#t(){if(!this.#Y||!this.#K)return;let J=Math.ceil(this.getBoundingClientRect().width),Q=Math.ceil(this.#K.getBoundingClientRect().width),Z=Math.max(J,Q,96);this.#Y.style.setProperty("width","max-content","important"),this.#Y.style.setProperty("min-width",`${Z}px`,"important"),this.#Y.style.setProperty("max-width","min(20rem, calc(100vw - 1rem))","important")}#s(){if(!this.#Y||T(this,"disabled"))return;if(this.#K)this.#Y.anchor=this.#K;this.#c(),this.#Q=!1,this.#z=null,this.#X=null,this.#B(),this.#t(),this.#Y.open=!0,document.addEventListener("keydown",this.#V,!0),this.#K?.setAttribute("aria-expanded","true"),this.#U=-1,requestAnimationFrame(()=>{this.#t(),this.#p();let J=this.#f(),Z=this.#XJ().findIndex(($)=>this.#y($)===this.value);if(Z>=0)this.#G(Z);else if(this.#K?.hasAttribute("data-focus-visible")||this.#K?.matches?.(":focus-visible"))this.#G(0);J?.syncOverflow?.(),this.#Q=!0,this.#A()})}#NJ(){if(!this.#Y)return;this.#Q=!1,this.#z=null,this.#X=null,document.removeEventListener("keydown",this.#V,!0),this.#Y.open=!1,this.#K?.setAttribute("aria-expanded","false")}}A("fig-select",c);var QJ=["srgb","srgb-linear","display-p3","oklab","oklch","hsl"],ZJ=["shorter","longer","increasing","decreasing"],E=new Set(["oklch","hsl"]);function N(J){let Q={...J??{}},Z=String(Q.interpolationSpace??"srgb").toLowerCase();if(!QJ.includes(Z))Z="srgb";Q.interpolationSpace=Z;let $=String(Q.hueInterpolation??"shorter").toLowerCase();return Q.hueInterpolation=ZJ.includes($)?$:"shorter",Q}function S(J){let Q=N(J);return Q.interpolationSpace="srgb",delete Q.hueInterpolation,Q}function P(J){let Q=S(J),Z={...Q,interpolationSpace:Q.interpolationSpace};if(E.has(Q.interpolationSpace))Z.hueInterpolation=Q.hueInterpolation;else delete Z.hueInterpolation;return Z}function $J(J){let Q=N(J);if(Q.interpolationSpace==="srgb")return"";if(E.has(Q.interpolationSpace))return`in ${Q.interpolationSpace} ${Q.hueInterpolation} hue`;return`in ${Q.interpolationSpace}`}function g(J){let Q=N(J);if(E.has(Q.interpolationSpace))return`${Q.interpolationSpace}-${Q.hueInterpolation||"shorter"}`;return Q.interpolationSpace}function F(J){let Q=String(J??"");for(let Z of E){let $=`${Z}-`;if(Q.startsWith($))return{interpolationSpace:Z,hueInterpolation:Q.slice($.length)||"shorter"}}return{interpolationSpace:Q||"srgb",hueInterpolation:"shorter"}}var XJ=0;class y extends HTMLElement{static#K=[{value:"srgb",space:"srgb",title:"Classic",subtitle:"sRGB Linear"},{value:"oklab",space:"oklab",title:"Smooth",subtitle:"OKLab"},{value:"oklch-increasing",space:"oklch",title:"Vibrant",subtitle:"OKLCH Increasing"},{value:"hsl-increasing",space:"hsl",title:"Vivid",subtitle:"HSL Increasing"},{value:"oklch-decreasing",space:"oklch",title:"Vibrant",subtitle:"OKLCH Decreasing",advanced:!0},{value:"hsl-decreasing",space:"hsl",title:"Vivid",subtitle:"HSL Decreasing",advanced:!0}];static#Y(J){let Q=y.#K,Z=Q.find((K)=>K.value===J);if(Z)return Z;let $=F(J),X=Q.find((K)=>K.space===$.interpolationSpace),Y=X?.subtitle.split(" ")[0]??$.interpolationSpace.toUpperCase(),j=$.hueInterpolation;return{value:J,space:$.interpolationSpace,title:X?.title??"Custom",subtitle:E.has($.interpolationSpace)?`${Y} ${j.charAt(0).toUpperCase()}${j.slice(1)}`:Y}}#j=null;#W=null;#J=null;#_=`fig-fill-picker-dialog-${++XJ}`;#R="solid";anchorElement=null;#U="solid";#k="srgb";#$={h:0,s:0,v:85,a:1};#L="hex";#Q={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}]};#z={url:null,scaleMode:"fill",scale:50};#X={url:null,poster:null,scaleMode:"fill",scale:50,opacity:1,missing:!0};#Z={stream:null,live:!0,snapshot:null,deviceId:null,scaleMode:"fill",scale:50,opacity:1};#w=null;#F=!1;#N=null;#V={};#u={};#q=null;#H=null;#M=null;#f=null;#D=!1;#T=!1;#C=null;#m=null;#c=null;#E=null;#$J=null;#b=0;#d=null;#l=null;#o=new Set;#g=new Set;constructor(){super();this.#d=this.#LJ.bind(this),this.#l=this.#XJ.bind(this)}static get observedAttributes(){return["value","disabled","alpha","mode","webcam-mode","default-video","aria-label","aria-labelledby","aria-describedby"]}connectedCallback(){this.style.display="contents",this.#B(()=>{this.#MJ(),this.#a(),this.#G()})}disconnectedCallback(){if(this.#IJ({stopWebcam:!0}),this.#TJ(),this.#kJ(),this.#W)this.#W.removeAttribute("selected");if(this.#j)this.#j.removeEventListener("click",this.#d),this.#j.removeEventListener("keydown",this.#l);this.#j=null,this.#W=null}#A(){return this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false"}#p(){return this.getAttribute("webcam-mode")==="snapshot"?"snapshot":"live"}#WJ(){return this.#U==="webcam"&&this.#p()==="live"&&this.#Z.live!==!1}#qJ(){return{live:this.#p()==="live"&&this.#Z.live!==!1,snapshot:this.#Z.snapshot??null,deviceId:this.#Z.deviceId??null,scaleMode:this.#Z.scaleMode||"fill",scale:this.#Z.scale??50,opacity:this.#Z.opacity??1}}#HJ(){let J=this.#X.url??null;return{url:J,poster:this.#X.poster??null,scaleMode:this.#X.scaleMode||"fill",scale:this.#X.scale??50,opacity:this.#X.opacity??1,...J?{}:{missing:!0}}}#BJ(J){if(J.webcam&&typeof J.webcam==="object"){let{stream:Q,snapshot:Z,...$}=J.webcam;if(Object.assign(this.#Z,$),typeof Z==="string"&&Z)this.#Z.snapshot=Z;return}if(J.type==="webcam"&&J.image){if(J.image.url!=null)this.#Z.snapshot=J.image.url;if(J.image.scaleMode)this.#Z.scaleMode=J.image.scaleMode;if(J.image.scale!=null)this.#Z.scale=J.image.scale}}#P(){this.dispatchEvent(new CustomEvent("webcamstream",{bubbles:!0,composed:!0,detail:{stream:this.#Z.stream,deviceId:this.#Z.deviceId??null}}))}get webcamStream(){return this.#Z.stream}releaseWebcam(){this.#YJ()}#y(J){if(!J)return null;if(this.#Z.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#Z.snapshot),this.#g.delete(this.#Z.snapshot);return this.#Z.snapshot=URL.createObjectURL(J),this.#g.add(this.#Z.snapshot),this.#Z.snapshot}#RJ(J,Q,Z){if(typeof J.getImageData!=="function")return!1;let $;try{$=J.getImageData(0,0,Q,Z).data}catch{return!1}let X=Math.max(1,Math.floor(Q*Z/256)),Y=0,j=0,K=0;for(let U=0;U<$.length;U+=X*4){let z=Math.max($[U],$[U+1],$[U+2]);if(Y=Math.max(Y,z),K+=1,z>24)j+=1}if(!K)return!0;return Y<=40||j/K<0.04}async#_J(J){let Q=[],Z=this.#Z.stream?.getVideoTracks?.()?.[0];if(Z&&typeof ImageCapture==="function")try{if(this.#N?.track!==Z)this.#N=new ImageCapture(Z);Q.push(await this.#N.grabFrame())}catch{this.#N=null}if(typeof createImageBitmap==="function")try{Q.push(await createImageBitmap(J))}catch{}return Q.push(J),Q.filter(Boolean)}async#UJ(J,Q,Z,$){let X=await this.#_J(Q);for(let Y of X){try{J.drawImage(Y,0,0,Z,$)}catch{continue}finally{Y.close?.()}if(!this.#RJ(J,Z,$))return!0}return!1}#zJ(J){return new Promise((Q)=>{if(typeof J.requestVideoFrameCallback==="function"){let Z=setTimeout(()=>Q(!1),400);J.requestVideoFrameCallback(()=>{clearTimeout(Z),Q(!0)});return}setTimeout(()=>Q(!1),200)})}async#OJ(J){if(!J?.videoWidth||!J.videoHeight)return null;let Q=document.createElement("canvas");Q.width=J.videoWidth,Q.height=J.videoHeight;let Z=Q.getContext("2d",{willReadFrequently:!0});if(!Z)return null;if(!await this.#UJ(Z,J,Q.width,Q.height))return null;let X=await new Promise((Y)=>Q.toBlob(Y,"image/png"));return this.#y(X)}#GJ(J){if(this.#U!=="webcam")return;let Q=this.#Z.stream;if(!Q)return;if(this.#w===Q&&this.#Z.snapshot){this.#G();return}if(this.#F)return;this.#F=!0;let Z=(X)=>{if(this.#F=!1,!X||this.#U!=="webcam"||this.#Z.stream!==Q)return;this.#w=Q,this.#G(),this.#O()},$=async()=>{let X=await this.#OJ(J);if(X){Z(X);return}if(this.#U!=="webcam"||this.#Z.stream!==Q){this.#F=!1;return}return await this.#zJ(J),$()};$()}#B(J){let Q=requestAnimationFrame(()=>{if(this.#o.delete(Q),this.isConnected)J()});return this.#o.add(Q),Q}#TJ(){this.#o.forEach((J)=>cancelAnimationFrame(J)),this.#o.clear()}#kJ(){let J=new Set([this.#Z.snapshot,this.#X.poster,this.#z.url].filter((Q)=>typeof Q==="string"&&Q.startsWith("blob:")));this.#g.forEach((Q)=>{if(!J.has(Q))URL.revokeObjectURL(Q)}),this.#g.clear(),J.forEach((Q)=>this.#g.add(Q))}#MJ(){let J=Array.from(this.children).find((Q)=>!Q.getAttribute("slot")?.startsWith("mode-"));if(!J)this.#W=document.createElement("fig-swatch"),this.#W.setAttribute("background","#D9D9D9"),this.appendChild(this.#W),this.#j=this.#W;else if(J.matches("fig-swatch, fig-chit"))this.#W=J,this.#j=J;else this.#j=J,this.#W=null;if(this.#S(),this.#j.removeEventListener("click",this.#d),this.#j.addEventListener("click",this.#d),this.#j.removeEventListener("keydown",this.#l),this.#j.addEventListener("keydown",this.#l),this.#W)this.#B(()=>{let Q=this.#W.querySelector('input[type="color"]');if(Q)Q.remove();this.#S()})}#n(){return this.getAttribute("aria-label")||"Fill picker"}#S(){if(!this.#j)return;let J=this.#A(),Q=this.getAttribute("aria-labelledby");if(!this.#j.hasAttribute("role"))this.#j.setAttribute("role","button");if(this.#j.setAttribute("tabindex",J?"-1":"0"),this.#j.setAttribute("aria-disabled",J?"true":"false"),this.#j.setAttribute("aria-haspopup","dialog"),this.#j.setAttribute("aria-expanded",this.#J?.open?"true":"false"),this.#j.setAttribute("aria-controls",this.#_),this.#j.removeAttribute("aria-hidden"),Q)this.#j.setAttribute("aria-labelledby",Q),this.#j.removeAttribute("aria-label");else if(this.hasAttribute("aria-label"))this.#j.setAttribute("aria-label",`Open ${this.#n()}`),this.#j.removeAttribute("aria-labelledby");else if(this.#j.removeAttribute("aria-labelledby"),!this.#j.hasAttribute("aria-label"))this.#j.setAttribute("aria-label",`Open ${this.#n()}`);let Z=this.getAttribute("aria-describedby");if(Z)this.#j.setAttribute("aria-describedby",Z);else this.#j.removeAttribute("aria-describedby")}#LJ(J){if(this.#A())return;J.stopPropagation(),J.preventDefault(),this.#s()}#XJ(J){if(J.key!=="Enter"&&J.key!==" ")return;if(this.#A())return;J.preventDefault(),J.stopPropagation(),this.#s()}#a(){let J=this.getAttribute("value");if(!J)return;let Q=["solid","gradient","image","video","webcam"];try{let Z=JSON.parse(J);if(Z.type)this.#U=Z.type;if(Z.color){if(typeof Z.color==="string")this.#$=this.#ZJ(Z.color);else if(typeof Z.color==="object"&&Z.color.h!==void 0)this.#$=Z.color}let $=Z.alpha!==void 0?Number(Z.alpha):Z.opacity!==void 0?Number(Z.opacity)/100:void 0;if(Number.isFinite($))this.#$.a=Math.max(0,Math.min(1,$));if(this.#k="srgb",Z.gradient)this.#Q=S({...this.#Q,...Z.gradient});if(Z.image)this.#z={...this.#z,...Z.image};if(Z.video)this.#X={...this.#X,...Z.video},this.#X.missing=!this.#X.url;if(this.#BJ(Z),Z.type&&!Q.includes(Z.type)){let{type:X,...Y}=Z;this.#u[Z.type]=Y}}catch(Z){if(J.startsWith("#"))this.#U="solid",this.#$=this.#ZJ(J)}}#G(){if(!this.#W)return;let J,Q="cover",Z="center";switch(this.#U){case"solid":J=this.#h(this.#$);break;case"gradient":J=this.#hJ();break;case"image":if(this.#z.url){J=I(this.#z.url);let $=this.#t(this.#z.scaleMode,this.#z.scale);Q=$.size,Z=$.position}else J="";break;case"video":if(this.#X.poster){J=I(this.#X.poster);let $=this.#t(this.#X.scaleMode,this.#X.scale);Q=$.size,Z=$.position}else J="";break;case"webcam":if(this.#Z.snapshot){J=I(this.#Z.snapshot);let $=this.#t(this.#Z.scaleMode,this.#Z.scale);Q=$.size,Z=$.position}else J="";break;default:{J=(this.#V[this.#U]?.element||this.querySelector(`[slot="mode-${this.#U}"]`))?.getAttribute("swatch-background")||"";break}}if(this.#W.setAttribute("background",J),this.#W.style.setProperty("--swatch-bg-size",Q),this.#W.style.setProperty("--swatch-bg-position",Z),this.#U==="solid")this.#W.setAttribute("alpha",this.#$.a);else this.#W.removeAttribute("alpha")}#t(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"}}}#s(){if(this.#A())return;if(!this.#J)this.#pJ();else this.#J.anchor=this.anchorElement||this.#j;if(this.#c=JSON.stringify(this.value),this.#E=this.#c,this.#VJ(this.#U,{emit:!1}),this.#W)this.#W.setAttribute("selected","true");this.#J.open=!0,this.#S(),this.#B(()=>{this.#J?.querySelector(".fig-fill-picker-close, .fig-fill-picker-type, fig-button, button, input, [tabindex='0']")?.focus?.(),this.#B(()=>{this.#i(),this.#v()})})}open(){this.#s()}close(){if(this.#J)this.#J.open=!1,this.#S()}#NJ(){if(!this.#J)return;for(let[J,{element:Q}]of Object.entries(this.#V)){let Z=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find(($)=>$.dataset.tab===J);if(!Z)continue;while(Z.firstChild)Q.appendChild(Z.firstChild)}}#IJ({stopWebcam:J=!1}={}){if(this.#C)this.#C(),this.#C=null;if(this.#m?.disconnect(),this.#m=null,!J&&this.#WJ())this.#xJ();else this.#YJ();if(!this.#J)return;this.#NJ(),this.#J.remove(),this.#J=null,this.#$J=null,this.#c=null,this.#E=null,this.#q=null,this.#H=null,this.#M=null,this.#f=null,this.#T=!1,this.#S()}#xJ(){this.#b+=1;let J=this.#J?.querySelector(".fig-fill-picker-webcam-video");if(J)J.srcObject=null}#YJ({emit:J=!0}={}){this.#b+=1;let Q=Boolean(this.#Z.stream);if(this.#Z.stream)this.#Z.stream.getTracks().forEach(($)=>$.stop()),this.#Z.stream=null;this.#w=null,this.#F=!1,this.#N=null;let Z=this.#J?.querySelector(".fig-fill-picker-webcam-video");if(Z)Z.srcObject=null;if(Q&&J)this.#P()}#pJ(){this.#V={},this.querySelectorAll('[slot^="mode-"]').forEach((O)=>{let f=O.getAttribute("slot").slice(5);this.#V[f]={element:O,label:O.getAttribute("label")||f.charAt(0).toUpperCase()+f.slice(1)}}),this.#J=document.createElement("dialog",{is:"fig-popup"}),this.#J.setAttribute("is","fig-popup"),this.#J.id=this.#_,this.#J.setAttribute("aria-label",this.#n()),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.#j;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"],Z={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},$=this.getAttribute("mode"),X;if($){if(X=$.split(",").map((f)=>f.trim().toLowerCase()).filter((f)=>Q.includes(f)||this.#V[f]),X.length===0)X=[...Q]}else X=[...Q];let Y={...Z};for(let[O,{label:f}]of Object.entries(this.#V))Y[O]=f;if(!X.includes(this.#U))this.#U=X[0],this.#R=X[0];let j;if(X.length===1)j=G("h3",{className:"fig-fill-picker-type-label"},Y[X[0]]);else{let O=G("fig-select-options",{},X.map((f)=>G("fig-select-option",{value:f},Y[f])));j=G("fig-select",{className:"fig-fill-picker-type",label:"Fill type",variant:"ghost",value:this.#U},O)}let K=X.map((O)=>G("div",{className:"fig-fill-picker-tab","data-tab":O})),U=G("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-close","aria-label":"Close fill picker"},C("close"));this.#J.replaceChildren(G("fig-header",{},[j,U]),G("fig-content",{},K)),document.body.appendChild(this.#J);for(let[O,{element:f}]of Object.entries(this.#V)){let H=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((R)=>R.dataset.tab===O);if(!H)continue;while(f.firstChild)H.appendChild(f.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:O,container:H}}))}let z=this.#J.querySelector(".fig-fill-picker-type");if(z)z.addEventListener("change",(O)=>{let f=typeof O.detail==="string"?O.detail:O.target?.value;if(f)this.#VJ(f)});this.#J.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#J.open=!1});let L=()=>{if(this.#W)this.#W.removeAttribute("selected");if(this.#WJ())this.#xJ();else this.#YJ();let O=JSON.stringify(this.value);if(this.#E!==null&&this.#E!==O)this.#x();this.#c=null,this.#E=null,this.#S();let f=this.#j;this.#B(()=>{if(f?.isConnected)HTMLElement.prototype.focus.call(f)}),this.dispatchEvent(new CustomEvent("close"))};this.#J.addEventListener("close",L);let W={solid:()=>this.#iJ(),gradient:()=>this.#nJ(),image:()=>this.#XQ(),video:()=>this.#jQ(),webcam:()=>this.#WQ()};for(let[O,f]of Object.entries(W))if(!this.#V[O]&&X.includes(O))f();for(let O of Object.keys(this.#V)){if(Q.includes(O))continue;let f=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((H)=>H.dataset.tab===O);if(!f)continue;f.addEventListener("input",(H)=>{if(H.target===this)return;if(H.stopPropagation(),H.detail)this.#u[O]=H.detail;this.#O()}),f.addEventListener("change",(H)=>{if(H.target===this)return;if(H.stopPropagation(),H.detail)this.#u[O]=H.detail;this.#x()})}}#VJ(J,{emit:Q=!0}={}){let Z=Array.from(this.#J?.querySelectorAll(".fig-fill-picker-tab")??[]).find((K)=>K.dataset.tab===J);if(!Z)return;let $=this.#R;if(this.#R=J,this.#U=J,$==="webcam"&&J!=="webcam")this.#YJ();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((K)=>{if(K.dataset.tab===J)K.style.display="block";else K.style.display="none"});let j=this.#J.querySelector("fig-content");if(j)j.style.padding=this.#V[J]?"0":"";if(J==="gradient")this.#B(()=>{this.#I();let K=Z.querySelector(".fig-fill-picker-gradient-bar-input");K?.refreshLayout?.(),this.#B(()=>{K?.refreshLayout?.()})});if(J==="video")this.#fJ();if(J==="webcam")this.#Z.live=this.#p()==="live",this.#$J?.(this.#Z.deviceId);if(this.#G(),Q)this.#O()}#sJ(){if(!this.#J?.open)return;if(this.#VJ(this.#U,{emit:!1}),this.#i(),this.#v(),this.#e(),this.#M)this.#M.setAttribute("value",this.#$.h);if(this.#f)this.#f.setAttribute("value",this.#$.a*100),this.#f.setAttribute("color",this.#h(this.#$));this.#I();let J=this.#J.querySelector('[data-tab="image"]'),Q=J?.querySelector(".fig-fill-picker-scale-mode"),Z=J?.querySelector(".fig-fill-picker-scale"),$=J?.querySelector(".fig-fill-picker-image-preview");if(Q)Q.value=this.#z.scaleMode;if(Z)Z.setAttribute("value",this.#z.scale),Z.style.display=this.#z.scaleMode==="tile"?"block":"none";if($)this.#r($);let X=this.#J.querySelector('[data-tab="video"]'),Y=X?.querySelector(".fig-fill-picker-scale-mode"),j=X?.querySelector(".fig-fill-picker-video-preview");if(Y)Y.value=this.#X.scaleMode;if(j)this.#JJ(j)}#iJ(){let J=this.#J.querySelector('[data-tab="solid"]'),Q=this.getAttribute("alpha")!=="false",Z=G("canvas",{width:"200",height:"200"}),$=G("fig-handle",{"aria-label":"Color saturation and brightness",role:"slider","aria-valuemin":"0","aria-valuemax":"100",type:"color",color:this.#h({...this.#$,a:1}),"data-no-color-picker":!0,drag:!0,"drag-surface":".fig-fill-picker-color-area","drag-axes":"x,y","drag-snapping":"modifier"}),X=G("fig-preview",{className:"fig-fill-picker-color-area"},[Z,$]),Y=G("fig-tooltip",{text:"Sample color"},G("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-eyedropper","aria-label":"Sample color"},C("eyedropper"))),j=G("div",{className:`fig-fill-picker-sliders${Q?"":" is-hue-only"}`},[Y,G("fig-slider",{type:"hue",variant:"classic",text:"false",min:"0",max:"360","aria-label":"Hue",value:this.#$.h}),Q?G("fig-slider",{type:"opacity",variant:"classic",text:"false",min:"0",max:"100","aria-label":"Opacity",value:this.#$.a*100,color:this.#h(this.#$)}):null]),K=G("fig-select-options",{},[["hex","Hex"],["rgb","RGB"],["css","CSS"],["hsl","HSL"],["hsb","HSB"],["lab","LAB"],["lch","LCH"]].map(([W,O])=>G("fig-select-option",{value:W},O))),U=G("fig-field",{className:"fig-fill-picker-inputs"},[G("fig-select",{className:"fig-fill-picker-input-mode",label:"Color value format",value:this.#L},K),G("span",{className:"fig-fill-picker-input-fields"})]);if(J.replaceChildren(X,j,U),this.#q=J.querySelector("canvas"),this.#H=J.querySelector("fig-handle"),this.#yJ(),this.#i(),this.#v(),this.#wJ(),this.#M=J.querySelector('fig-slider[type="hue"]'),this.#M.addEventListener("input",(W)=>{this.#$.h=parseFloat(W.target.value),this.#i(),this.#v(),this.#e(),this.#O()}),this.#M.addEventListener("change",()=>{this.#x()}),Q)this.#f=J.querySelector('fig-slider[type="opacity"]'),this.#f.addEventListener("input",(W)=>{this.#$.a=parseFloat(W.target.value)/100,this.#e(),this.#O()}),this.#f.addEventListener("change",()=>{this.#x()});J.querySelector(".fig-fill-picker-input-mode").addEventListener("change",(W)=>{let O=typeof W.detail==="string"?W.detail:W.target?.value;if(!O)return;this.#L=O,this.#uJ()}),this.#uJ();let L=J.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)L.addEventListener("click",async()=>{try{let O=await new EyeDropper().open();this.#$={...this.#ZJ(O.sRGBHex),a:this.#$.a},this.#i(),this.#v(),this.#e(),this.#O()}catch(W){}});else L.setAttribute("disabled",""),L.title="EyeDropper not supported in this browser"}#RQ(){let J=this.#J?.querySelector('[data-tab="solid"]');if(J){let Q=J.querySelector("canvas");if(Q){let Z=document.createElement("canvas");Z.width=Q.width,Z.height=Q.height,Q.replaceWith(Z),this.#q=Z,this.#wJ()}this.#i(),this.#v()}this.#KJ(),this.#O()}#i(){if(!this.#q&&this.#J)this.#q=this.#J.querySelector('[data-tab="solid"] canvas');if(!this.#q)return;let J=this.#k==="display-p3"?"display-p3":"srgb",Q=this.#q.getContext("2d",{colorSpace:J});if(!Q)return;let Z=this.#q.width,$=this.#q.height;Q.clearRect(0,0,Z,$);let X=this.#$.h,Y=this.#k==="display-p3",j=Q.createLinearGradient(0,0,Z,0);if(Y){j.addColorStop(0,"color(display-p3 1 1 1)");let[U,z,L]=hslToP3(X,100,50);j.addColorStop(1,`color(display-p3 ${U} ${z} ${L})`)}else j.addColorStop(0,"#FFFFFF"),j.addColorStop(1,`hsl(${X}, 100%, 50%)`);Q.fillStyle=j,Q.fillRect(0,0,Z,$);let K=Q.createLinearGradient(0,0,0,$);K.addColorStop(0,"rgba(0,0,0,0)"),K.addColorStop(1,"rgba(0,0,0,1)"),Q.fillStyle=K,Q.fillRect(0,0,Z,$)}#v(J=0){if(!this.#H||!this.#q)return;this.#yJ();let Q=this.#q.getBoundingClientRect();if((Q.width===0||Q.height===0)&&J<5){this.#B(()=>this.#v(J+1));return}let Z=Math.max(0,Math.min(100,this.#$.s)),$=Math.max(0,Math.min(100,100-this.#$.v));this.#H.setAttribute("value",`${Z}% ${$}%`),this.#H.setAttribute("color",this.#h({...this.#$,a:1}))}#yJ(){if(!this.#H)return;this.#H.setAttribute("aria-valuenow",String(Math.round(this.#$.v))),this.#H.setAttribute("aria-valuetext",`Saturation ${Math.round(this.#$.s)}%, brightness ${Math.round(this.#$.v)}%`),this.#H.removeAttribute("aria-pressed")}#DJ(J,Q,Z={}){let{updateHandle:$=!0,emitInput:X=!0,emitChange:Y=!1}=Z;if(this.#$.s=Math.max(0,Math.min(100,J*100)),this.#$.v=Math.max(0,Math.min(100,(1-Q)*100)),this.#H)this.#H.setAttribute("color",this.#h({...this.#$,a:1})),this.#yJ();if($)this.#v();if(this.#e(),X)this.#O();if(Y)this.#x()}#wJ(){if(this.#C)this.#C(),this.#C=null;if(!this.#q||!this.#H)return;let J=this.#q.parentElement||this.#q,Q=this.#H,Z=!1,$=(z,L={})=>{let W=J.getBoundingClientRect();if(W.width===0||W.height===0)return;let O=Math.max(0,Math.min(z.clientX-W.left,W.width)),f=Math.max(0,Math.min(z.clientY-W.top,W.height));this.#DJ(O/W.width,f/W.height,L)},X=(z)=>{if(z.button!==0)return;if(z.target===Q||Q.contains(z.target))return;Z=!0,this.#D=!0,J.setPointerCapture(z.pointerId),$(z,{updateHandle:!0,emitInput:!0})},Y=(z)=>{if(!Z)return;if(z.buttons===0){j();return}$(z,{updateHandle:!0,emitInput:!0})},j=()=>{if(!Z)return;Z=!1,this.#D=!1,this.#x()},K=(z)=>{this.#D=!0;let L=z.detail?.px,W=z.detail?.py;if(!Number.isFinite(L)||!Number.isFinite(W))return;Q.setAttribute("value",`${L*100}% ${W*100}%`),this.#DJ(L,W,{updateHandle:!1,emitInput:!0})},U=(z)=>{let L=z.detail?.px,W=z.detail?.py;if(Number.isFinite(L)&&Number.isFinite(W))Q.setAttribute("value",`${L*100}% ${W*100}%`),this.#DJ(L,W,{updateHandle:!1,emitInput:!1});this.#D=!1,this.#x()};J.addEventListener("pointerdown",X),J.addEventListener("pointermove",Y),J.addEventListener("pointerup",j),J.addEventListener("pointercancel",j),J.addEventListener("lostpointercapture",j),Q.addEventListener("input",K),Q.addEventListener("change",U),this.#C=()=>{J.removeEventListener("pointerdown",X),J.removeEventListener("pointermove",Y),J.removeEventListener("pointerup",j),J.removeEventListener("pointercancel",j),J.removeEventListener("lostpointercapture",j),Q.removeEventListener("input",K),Q.removeEventListener("change",U),this.#D=!1}}#uJ(){let J=this.#J?.querySelector(".fig-fill-picker-input-fields");if(!J)return;let Q=(K,U)=>G("fig-tooltip",{text:K},U),Z=(K,U,z,L,W,O)=>G("fig-input-number",{className:K,"aria-label":U,min:z,max:L,step:W,units:O}),$=this.getAttribute("alpha")!=="false",X=()=>$?Q("Alpha",Z("fig-fill-picker-ci-a","Alpha",0,100,0.1,"%")):null,Y=(K,U="")=>G("div",{className:["input-combo",U].filter(Boolean).join(" ")},K),j;switch(this.#L){case"rgb":j=Y([Q("Red",Z("fig-fill-picker-ci-r","Red",0,255)),Q("Green",Z("fig-fill-picker-ci-g","Green",0,255)),Q("Blue",Z("fig-fill-picker-ci-b","Blue",0,255)),X()]);break;case"hsl":j=Y([Q("Hue",Z("fig-fill-picker-ci-h","Hue",0,360)),Q("Saturation",Z("fig-fill-picker-ci-s","Saturation",0,100)),Q("Lightness",Z("fig-fill-picker-ci-l","Lightness",0,100)),X()]);break;case"hsb":j=Y([Q("Hue",Z("fig-fill-picker-ci-h","Hue",0,360)),Q("Saturation",Z("fig-fill-picker-ci-s","Saturation",0,100)),Q("Brightness",Z("fig-fill-picker-ci-v","Brightness",0,100)),X()]);break;case"lab":j=Y([Q("Lightness",Z("fig-fill-picker-ci-okl","Lightness",0,100)),Q("Green-Red axis",Z("fig-fill-picker-ci-oka","Green-Red axis",-0.4,0.4,0.001)),Q("Blue-Yellow axis",Z("fig-fill-picker-ci-okb","Blue-Yellow axis",-0.4,0.4,0.001)),X()]);break;case"lch":j=Y([Q("Lightness",Z("fig-fill-picker-ci-okl","Lightness",0,100)),Q("Chroma",Z("fig-fill-picker-ci-okc","Chroma",0,0.4,0.001)),Q("Hue",Z("fig-fill-picker-ci-okh","Hue",0,360)),X()]);break;case"css":j=G("fig-input-text",{className:"fig-fill-picker-ci-css","aria-label":"CSS color",placeholder:"rgba(0, 0, 0, 1)"});break;default:{let K=G("fig-input-text",{className:"fig-fill-picker-ci-hex","aria-label":"Hex color",placeholder:"FFFFFF"});j=$?Y([K,X()],"fig-fill-picker-ci-hex-row"):K}break}J.replaceChildren(j),this.#rJ(),this.#B(()=>this.#e())}#rJ(){let J=this.#J?.querySelector(".fig-fill-picker-input-fields");if(!J)return;let Q=()=>{if(this.#D)return;let X=this.#oJ();if(!X)return;let Y=Number.isFinite(X.a)?X.a:this.#$.a;if(this.#$={...X,a:Y},this.#i(),this.#v(),this.#M)this.#M.setAttribute("value",this.#$.h);if(this.#f&&Number.isFinite(X.a))this.#f.setAttribute("value",this.#$.a*100);this.#O()},Z=()=>this.#x();J.querySelectorAll("fig-input-number, fig-input-text").forEach((X)=>{X.addEventListener("input",Q),X.addEventListener("change",Z)})}#lJ(){let J=this.#J?.querySelector(".fig-fill-picker-ci-a");if(!J)return;let Q=parseFloat(J.value);if(!Number.isFinite(Q))return;return Math.max(0,Math.min(1,Q/100))}#oJ(){let J=($)=>this.#J?.querySelector(`.${$}`),Q=($)=>parseFloat(J($)?.value??0),Z=($)=>{if(!$)return null;let X=this.#lJ();return{...$,a:X??$.a??this.#$.a}};switch(this.#L){case"rgb":return Z(this.#QJ({r:Q("fig-fill-picker-ci-r"),g:Q("fig-fill-picker-ci-g"),b:Q("fig-fill-picker-ci-b")}));case"hsl":{let $=this.#qQ({h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),l:Q("fig-fill-picker-ci-l")});return Z(this.#QJ($))}case"hsb":return Z({h:Q("fig-fill-picker-ci-h"),s:Q("fig-fill-picker-ci-s"),v:Q("fig-fill-picker-ci-v")});case"lab":{let $=this.#dJ({l:Q("fig-fill-picker-ci-okl")/100,a:Q("fig-fill-picker-ci-oka"),b:Q("fig-fill-picker-ci-okb")});return Z(this.#QJ($))}case"lch":{let $=this.#BQ({l:Q("fig-fill-picker-ci-okl")/100,c:Q("fig-fill-picker-ci-okc"),h:Q("fig-fill-picker-ci-okh")});return Z(this.#QJ($))}case"css":{let $=J("fig-fill-picker-ci-css");if(!$)return null;return this.#LQ($.value)}default:{let $=J("fig-fill-picker-ci-hex");if(!$)return null;let X=$.value.replace(/^#/,"");if(X.length===3)X=X[0]+X[0]+X[1]+X[1]+X[2]+X[2];if(X.length===8){let Y=parseInt(X.slice(6,8),16)/255;if(X=X.slice(0,6),!/^[0-9a-fA-F]{6}$/.test(X))return null;return{...this.#ZJ(`#${X}`),a:Y}}if(X.length!==6||!/^[0-9a-fA-F]{6}$/.test(X))return null;return Z(this.#ZJ(`#${X}`))}}}#e(){if(!this.#J)return;let J=this.#h(this.#$),Q=this.#SJ(this.#$),Z=(X)=>this.#J.querySelector(`.${X}`),$=(X,Y)=>{let j=Z(X);if(j)j.setAttribute("value",Y)};switch(this.#L){case"rgb":$("fig-fill-picker-ci-r",Q.r),$("fig-fill-picker-ci-g",Q.g),$("fig-fill-picker-ci-b",Q.b);break;case"hsl":{let X=this.#fQ(Q);$("fig-fill-picker-ci-h",Math.round(X.h)),$("fig-fill-picker-ci-s",Math.round(X.s)),$("fig-fill-picker-ci-l",Math.round(X.l));break}case"hsb":$("fig-fill-picker-ci-h",Math.round(this.#$.h)),$("fig-fill-picker-ci-s",Math.round(this.#$.s)),$("fig-fill-picker-ci-v",Math.round(this.#$.v));break;case"lab":{let X=this.#cJ(Q);$("fig-fill-picker-ci-okl",Math.round(X.l*100)),$("fig-fill-picker-ci-oka",+X.a.toFixed(3)),$("fig-fill-picker-ci-okb",+X.b.toFixed(3));break}case"lch":{let X=this.#HQ(Q);$("fig-fill-picker-ci-okl",Math.round(X.l*100)),$("fig-fill-picker-ci-okc",+X.c.toFixed(3)),$("fig-fill-picker-ci-okh",Math.round(X.h));break}case"css":$("fig-fill-picker-ci-css",this.#GQ(this.#$));break;default:$("fig-fill-picker-ci-hex",J.replace(/^#/,"").toUpperCase());break}if(this.#L!=="css"){let X=Math.round(this.#$.a*1000)/10;$("fig-fill-picker-ci-a",Number.isInteger(X)?X:+X.toFixed(1))}if(this.#f)this.#f.setAttribute("color",J);this.#G()}#nJ(){let J=this.#J.querySelector('[data-tab="gradient"]'),Q=G("fig-select",{className:"fig-fill-picker-gradient-type",label:"Gradient type",value:this.#Q.type},G("fig-select-options",{},[["linear","Linear"],["radial","Radial"],["angular","Angular"]].map(([z,L])=>G("fig-select-option",{value:z},L)))),Z=(z,L,W)=>G("fig-tooltip",{text:z},G("fig-button",{icon:!0,variant:"ghost",className:L,"aria-label":z},C(W))),$=G("div",{className:"fig-fill-picker-gradient-actions"},[Z("Flip gradient","fig-fill-picker-gradient-flip","swap"),Z("Rotate gradient","fig-fill-picker-gradient-rotate","rotate")]),X=G("fig-field",{className:"fig-fill-picker-gradient-header"},[Q,$]),Y=G("fig-input-gradient",{className:"fig-fill-picker-gradient-bar-input","aria-label":"Gradient stops",edit:"true",mode:"tip",size:"large",value:JSON.stringify({type:"gradient",gradient:P(this.#Q)})}),j=G("fig-preview",{className:"fig-fill-picker-gradient-preview"},Y),K=G("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-gradient-add","aria-label":"Add gradient stop",title:"Add stop"},C("add")),U=G("div",{className:"fig-fill-picker-gradient-stops"},[G("fig-header",{className:"fig-fill-picker-gradient-stops-header",borderless:!0},[G("span",{},"Stops"),K]),G("div",{className:"fig-fill-picker-gradient-stops-list"},document.createElement("fig-reorder"))]);J.replaceChildren(X,j,U),this.#I(),this.#aJ(J)}#_Q(){let J=({value:$,title:X,subtitle:Y,advanced:j=!1})=>G("fig-select-option",{value:$,label:`${X} — ${Y}`,className:j?"fig-fill-picker-gradient-interpolation-advanced":null},[G("fig-interpolation-swatch",{slot:"prepend",size:"large","aria-hidden":"true"}),G("span",{className:"fig-fill-picker-gradient-interpolation-label"},[G("span",{className:"fig-fill-picker-gradient-interpolation-title"},X),G("span",{className:"fig-fill-picker-gradient-interpolation-subtitle"},Y)])]),Q=G("fig-separator",{className:"fig-fill-picker-gradient-interpolation-advanced"}),Z=y.#K;return[...Z.filter(($)=>!$.advanced).map(J),Q,...Z.filter(($)=>$.advanced).map(J)]}#aJ(J){let Q=(V)=>typeof V.detail==="string"?V.detail:V.target?.value,Z=J.querySelector(".fig-fill-picker-gradient-bar-input"),$=(V)=>{if(!Z)return;this.#T=!0;try{Z.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(V)}))}finally{this.#T=!1}},X=()=>{$(this.#Q)};J.querySelector(".fig-fill-picker-gradient-type")?.addEventListener("change",(V)=>{let q=Q(V);if(!q)return;this.#Q.type=q,this.#I(),this.#O()});let j=J.querySelector(".fig-fill-picker-gradient-space"),K=j?.querySelector("fig-select-options"),U="fig-fill-picker-gradient-interpolation-collapsed",z=K?.querySelector(".fig-fill-picker-gradient-interpolation-advanced"),L=()=>Boolean(K?.classList.contains(U)),W=(V)=>{K?.querySelector(".fig-overflow-end")?.setAttribute("aria-label",V?"Show all color interpolation options":"Scroll down")},O=()=>{if(!K)return;K.classList.remove(U),K.style.removeProperty("max-height"),W(!1),K.syncOverflow?.()},f=()=>{if(!K||!z)return;K.style.removeProperty("max-height"),K.classList.add(U),K.scrollTop=0;let V=K.getBoundingClientRect().top,q=z.getBoundingClientRect().top,M=K.querySelector(".fig-overflow-end")?.offsetHeight||0,D=q-V;if(D>0)K.style.maxHeight=`${Math.round(D+M)}px`;W(!0),K.syncOverflow?.()},H=(V)=>Boolean(K?.querySelector(`fig-select-option.fig-fill-picker-gradient-interpolation-advanced[value="${V}"]`)),R=()=>{if(H(g(this.#Q)))O();else f()};if(K?.addEventListener("click",(V)=>{if(!L())return;if(!V.target?.closest?.(".fig-overflow-end"))return;V.preventDefault(),V.stopPropagation(),O()},!0),K?.addEventListener("focusin",(V)=>{if(!L())return;if(V.target?.closest?.(".fig-fill-picker-gradient-interpolation-advanced"))O()}),K?.addEventListener("scroll",()=>{if(L()&&K.scrollTop!==0)K.scrollTop=0}),j?.querySelectorAll("fig-select-option").forEach((V)=>{let q=()=>{let M=F(V.getAttribute("value")||"srgb");$(N({...this.#Q,...M}))};V.addEventListener("pointerenter",q),V.addEventListener("pointerleave",()=>{if(document.activeElement!==V)X()}),V.addEventListener("focus",q),V.addEventListener("blur",()=>{if(!V.matches(":hover"))X()})}),this.#m?.disconnect(),j)this.#m=new MutationObserver(()=>{if(!j.hasAttribute("open"))X();else this.#B(R)}),this.#m.observe(j,{attributes:!0,attributeFilter:["open"]});let _=J.querySelector(".fig-fill-picker-gradient-interpolation-modes");if(_?.addEventListener("change",(V)=>{let q=typeof V.detail==="string"?V.detail:V.target?.value;if(!q)return;let M=F(q);this.#Q=N({...this.#Q,...M}),this.#I(),this.#O()}),_?.querySelectorAll("fig-segment").forEach((V)=>{let q=()=>{$(N({...this.#Q,...F(V.getAttribute("value")||"srgb")}))};V.addEventListener("pointerenter",q),V.addEventListener("pointerleave",X)}),j?.addEventListener("change",(V)=>{let q=Q(V);if(!q)return;let M=F(q);this.#Q=N({...this.#Q,...M}),this.#I(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-rotate")?.addEventListener("click",()=>{this.#Q.angle=(Number(this.#Q.angle)+90)%360,this.#I(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#Q.stops.forEach((V)=>{V.position=100-V.position}),this.#Q.stops.sort((V,q)=>V.position-q.position),this.#I(),this.#O()}),J.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#Q.stops.push({position:50,color:"#888888",opacity:100}),this.#Q.stops.sort((q,M)=>q.position-M.position),this.#I(),this.#O()}),Z){let V=(q)=>{if(q.stopPropagation(),this.#T)return;let M=q.detail;if(!M?.gradient)return;this.#Q=S({...this.#Q,...M.gradient}),this.#G(),this.#jJ(),this.#bJ()};Z.addEventListener("input",(q)=>{V(q),this.#O()}),Z.addEventListener("change",(q)=>{V(q),this.#x()})}J.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(V)=>{this.#QQ(V)})}#FJ(J){let Q=String(J.color||"#888888").replace(/^#/,"").slice(0,6),Z=J.opacity??100;if(Z>=100)return`#${Q}`;let $=Math.round(Z/100*255).toString(16).padStart(2,"0");return`#${Q}${$}`}#tJ(J){if(!(J instanceof HTMLElement))return"#888888";if(J.hexOpaque)return this.#CJ(J.hexOpaque);let Q=J.value;if(typeof Q==="string"&&Q.startsWith("#"))return this.#CJ(Q.length>7?Q.slice(0,7):Q);let Z=J.querySelector('fig-input-text:not([type="number"])'),$=String(Z?.value??Z?.getAttribute("value")??"").replace(/#/g,"").slice(0,6);if(/^[0-9A-Fa-f]{6}$/.test($))return`#${$.toUpperCase()}`;let X=J.getAttribute("value");if(typeof X==="string"&&X.startsWith("#"))return this.#CJ(X.length>7?X.slice(0,7):X);return"#888888"}#CJ(J){let Q=String(J||"#888888").replace(/^#/,"").slice(0,6);if(!/^[0-9A-Fa-f]{6}$/.test(Q))return"#888888";return`#${Q.toUpperCase()}`}#eJ(J){let Q=J.querySelector(".fig-fill-picker-stop-position"),Z=J.querySelector(".fig-fill-picker-stop-color"),$=parseFloat(Q?.value??Q?.getAttribute("value")??"0")||0,X=this.#tJ(Z),Y=100;if(Z instanceof HTMLElement&&Z.rgba?.a!==void 0)Y=Math.round(Z.rgba.a*100);else{let j=parseInt(J.dataset.index,10);if(!isNaN(j)&&this.#Q.stops[j])Y=this.#Q.stops[j].opacity??100}return{position:$,color:X,opacity:Y}}#EJ(J){let Q=parseInt(J.dataset.index,10);if(isNaN(Q)||Q<0||Q>=this.#Q.stops.length)return;let Z={...this.#Q.stops[Q],...this.#eJ(J)};this.#Q.stops[Q]=Z,this.#JQ(J,Z)}#JQ(J,Q){let Z=J.querySelector(".fig-fill-picker-stop-position");if(Z)Z.setAttribute("value",String(Q.position));let $=J.querySelector(".fig-fill-picker-stop-color");if($)$.setAttribute("value",this.#FJ(Q))}#QQ(J){let{oldIndex:Q,newIndex:Z}=J.detail??{};if(Q==null||Z==null||Q===Z||Q<0||Z<0||Q>=this.#Q.stops.length||Z>=this.#Q.stops.length)return;let X=J.currentTarget.querySelectorAll(".fig-fill-picker-gradient-stop-row");X.forEach((j)=>this.#EJ(j));let[Y]=this.#Q.stops.splice(Q,1);this.#Q.stops.splice(Z,0,Y),X.forEach((j,K)=>{j.dataset.index=String(K)}),this.#T=!0;try{this.#jJ(),this.#KJ(),this.#O()}finally{this.#T=!1}}#I(){if(!this.#J)return;let J=this.#J.querySelector('[data-tab="gradient"]');if(!J)return;this.#Q=S(this.#Q);let Q=g(this.#Q),Z=J.querySelector(".fig-fill-picker-gradient-space");if(Z)Z.value=Q;let $=J.querySelector(".fig-fill-picker-gradient-interpolation-modes");if($){let X=y.#Y(Q),Y=$.querySelector(`fig-segment[value="${Q}"]`)||$.querySelector(`fig-segment[data-space="${X.space}"]`);if(Y){let j=`${X.title} — ${X.subtitle}`;Y.setAttribute("value",Q),Y.setAttribute("aria-label",j);let K=Y.closest("fig-tooltip");if(K)K.setAttribute("text",j);$.value=Q}}this.#jJ(),this.#KJ(),this.#bJ()}#ZQ(){let J=Array.isArray(this.#Q.stops)?[...this.#Q.stops].sort((Q,Z)=>(Q.position??0)-(Z.position??0)):[];if(J.length<2)return[{color:"#FF0000",position:0},{color:"#4F9EFF",position:100}];return J.map((Q)=>({color:String(Q.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:Q.position??0}))}#jJ(){if(!this.#J)return;let J=this.#ZQ();this.#J.querySelectorAll("fig-interpolation-swatch").forEach((Q)=>{let Z=Q.closest("fig-select-option, fig-segment")?.getAttribute("value")||"srgb",$=F(Z),X={type:"linear",stops:J,interpolationSpace:$.interpolationSpace};if(E.has($.interpolationSpace))X.hueInterpolation=$.hueInterpolation;Q.value={type:"gradient",gradient:X}})}#KJ(){if(!this.#J)return;let J=this.#J.querySelector(".fig-fill-picker-gradient-bar-input");if(J)this.#T=!0,J.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(this.#Q)})),this.#T=!1;this.#G()}#bJ(){if(!this.#J)return;let J=this.#J.querySelector(".fig-fill-picker-gradient-stops-list"),Q=J?.querySelector("fig-reorder");if(!J||!Q)return;let Z=Q.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(Z.length===this.#Q.stops.length){this.#Q.stops.forEach(($,X)=>{let Y=Z[X];Y.dataset.index=X;let j=Y.querySelector(".fig-fill-picker-stop-position");if(j)j.setAttribute("value",$.position);let K=Y.querySelector(".fig-fill-picker-stop-color");if(K)K.setAttribute("value",this.#FJ($));let U=Y.querySelector(".fig-fill-picker-stop-remove");if(U)if(this.#Q.stops.length<=2)U.setAttribute("disabled","");else U.removeAttribute("disabled")});return}this.#$Q(J)}#$Q(J){let Q=J.querySelector("fig-reorder");if(!Q)return;let Z=this.#Q.stops.map(($,X)=>G("fig-field",{className:"fig-fill-picker-gradient-stop-row","data-index":X},[G("fig-input-number",{className:"fig-fill-picker-stop-position","aria-label":"Gradient stop position",min:"0",max:"100",value:$.position,units:"%"}),G("fig-input-color",{className:"fig-fill-picker-stop-color","aria-label":"Gradient stop color",text:"true",alpha:"true",picker:"figma","picker-dialog-position":"right",value:this.#FJ($)}),G("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-stop-remove",disabled:this.#Q.stops.length<=2,"aria-label":"Remove gradient stop"},C("minus"))]));Q.replaceChildren(...Z),Q.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach(($)=>{$.querySelector(".fig-fill-picker-stop-position").addEventListener("input",()=>{this.#EJ($),this.#jJ(),this.#KJ(),this.#O()});let X=$.querySelector(".fig-fill-picker-stop-color"),Y=X.querySelector("fig-fill-picker");if(Y)Y.anchorElement=this.#J;else this.#B(()=>{let K=X.querySelector("fig-fill-picker");if(K)K.anchorElement=this.#J});let j=()=>{this.#EJ($),this.#T=!0;try{this.#jJ(),this.#KJ(),this.#O()}finally{this.#T=!1}};X.addEventListener("input",j),X.addEventListener("change",j),$.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{let K=parseInt($.dataset.index,10);if(this.#Q.stops.length>2)this.#Q.stops.splice(K,1),this.#I(),this.#O()})})}#AJ(J,Q=!0){let Z=N({...this.#Q,interpolationSpace:J??this.#Q.interpolationSpace}),$=this.#k==="display-p3",X=Z.stops.map((K)=>{let U=(K.opacity??100)/100;return`${$?this.#VQ(K.color,U):this.#zQ(K.color,U)} ${K.position}%`}).join(", "),Y=$J(Z),j=Q&&Y?` ${Y}`:"";switch(Z.type){case"linear":return`linear-gradient(${Z.angle}deg${j}, ${X})`;case"radial":return`radial-gradient(circle at ${Z.centerX}% ${Z.centerY}%${j}, ${X})`;case"angular":return`conic-gradient(from ${Z.angle}deg${j}, ${X})`;default:return`linear-gradient(${Z.angle}deg${j}, ${X})`}}static#gJ=new Map;#vJ(J){let Q=y.#gJ.get(J);if(Q!==void 0)return Q;let Z=document.createElement("div");Z.style.background=J;let $=!!Z.style.background;return y.#gJ.set(J,$),$}#hJ(){let J=this.#AJ(void 0,!0);if(this.#vJ(J))return J;let Q=this.#AJ("oklab",!0);if(this.#vJ(Q))return Q;return this.#AJ("oklab",!1)}#XQ(){let J=this.#J.querySelector('[data-tab="image"]'),Q=G("fig-select",{className:"fig-fill-picker-scale-mode",label:"Image scale mode",value:this.#z.scaleMode},G("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"],["tile","Tile"]].map(([Y,j])=>G("fig-select-option",{value:Y},j)))),Z=G("fig-input-number",{className:"fig-fill-picker-scale","aria-label":"Image tile scale",min:"1",max:"200",value:this.#z.scale,units:"%"});if(this.#z.scaleMode!=="tile")Z.style.display="none";let $=G("fig-field",{className:"fig-fill-picker-media-header"},[Q,Z]),X=G("fig-image",{className:"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"});J.replaceChildren($,X),this.#YQ(J)}#YQ(J){let Q=J.querySelector(".fig-fill-picker-scale-mode"),Z=J.querySelector(".fig-fill-picker-scale"),$=J.querySelector(".fig-fill-picker-image-preview");Q.addEventListener("change",(X)=>{let Y=typeof X.detail==="string"?X.detail:X.target?.value;if(!Y)return;this.#z.scaleMode=Y,Z.style.display=Y==="tile"?"block":"none",this.#r($),this.#G(),this.#O()}),Z.addEventListener("input",(X)=>{this.#z.scale=parseFloat(X.target.value)||100,this.#r($),this.#G(),this.#O()}),$.addEventListener("loaded",(X)=>{let Y=X.detail?.src||$.src;if(!Y)return;this.#z.url=Y,this.#r($),this.#G(),this.#O()}),$.addEventListener("change",()=>{if($.src)return;this.#z.url=null,this.#r($),this.#G(),this.#O()}),this.#r($)}#r(J){if(!this.#z.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.#z.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.#z.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.#z.url})`,J.style.backgroundPosition="top left",J.style.backgroundSize=`${this.#z.scale}%`,J.style.backgroundRepeat="repeat",J.mediaEl)J.mediaEl.style.opacity="0";break}}#JJ(J){if(J.tagName==="FIG-MEDIA"){if(!this.#X.url){J.removeAttribute("src"),J.classList.remove("has-media");return}if(J.setAttribute("src",this.#X.url),this.#X.poster)J.setAttribute("poster",this.#X.poster);else J.removeAttribute("poster");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.#X.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.#X.scaleMode){case"fill":case"crop":J.style.objectFit="cover";break;case"fit":J.style.objectFit="contain";break}}#jQ(){let J=this.#J.querySelector('[data-tab="video"]'),Q=G("fig-select",{className:"fig-fill-picker-scale-mode",label:"Video scale mode",value:this.#X.scaleMode},G("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"]].map(([X,Y])=>G("fig-select-option",{value:X},Y)))),Z=G("fig-field",{className:"fig-fill-picker-media-header"},Q),$=G("fig-media",{className:"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:!0,muted:"true",loop:"true"});J.replaceChildren(Z,$),this.#KQ(J),this.#fJ()}#mJ(){if(this.#X.poster?.startsWith("blob:"))URL.revokeObjectURL(this.#X.poster),this.#g.delete(this.#X.poster);this.#X.poster=null}#fJ({emit:J=!0}={}){if(this.#X.url){if(this.#X.missing=!1,!this.#X.poster)this.#PJ(this.#X.url,{emit:J});return}let Q=this.getAttribute("default-video");if(!Q){this.#X.missing=!0;return}this.#X.url=Q,this.#X.missing=!1;let Z=this.#J?.querySelector(".fig-fill-picker-video-preview");if(Z)this.#JJ(Z);this.#PJ(Q,{emit:J})}async#PJ(J,{emit:Q=!0}={}){if(!J)return;let Z=document.createElement("video");Z.muted=!0,Z.playsInline=!0,Z.preload="auto",Z.crossOrigin="anonymous";try{if(await new Promise((Y,j)=>{let K=()=>j(Error("video poster failed"));Z.addEventListener("error",K,{once:!0}),Z.addEventListener("loadeddata",Y,{once:!0}),Z.src=J}),!Z.videoWidth||!Z.videoHeight)return;let $=document.createElement("canvas");$.width=Z.videoWidth,$.height=Z.videoHeight,$.getContext("2d").drawImage(Z,0,0);let X=await new Promise((Y)=>$.toBlob(Y,"image/jpeg",0.85));if(!X)return;if(this.#mJ(),this.#X.poster=URL.createObjectURL(X),this.#g.add(this.#X.poster),this.#G(),Q)this.#O()}catch{}}#KQ(J){let Q=J.querySelector(".fig-fill-picker-scale-mode"),Z=J.querySelector(".fig-fill-picker-video-preview");Q.addEventListener("change",($)=>{let X=typeof $.detail==="string"?$.detail:$.target?.value;if(!X)return;this.#X.scaleMode=X,this.#JJ(Z),this.#G(),this.#O()}),Z.addEventListener("loaded",($)=>{let X=$.detail?.src||Z.src;if(!X)return;this.#X.url=X,this.#X.missing=!1,this.#JJ(Z),Z.play?.(),this.#PJ(X),this.#G(),this.#O()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#X.url=null,this.#mJ(),this.#fJ(),this.#JJ(Z),this.#G(),this.#O()}),this.#JJ(Z)}#WQ(){let J=this.#J.querySelector('[data-tab="webcam"]'),Q=G("fig-field",{className:"fig-fill-picker-webcam-camera"},G("fig-select",{className:"fig-fill-picker-camera-select",label:"Camera",full:!0},document.createElement("fig-select-options")));Q.style.display="none";let Z=G("video",{className:"fig-fill-picker-webcam-video",autoplay:!0,muted:!0,playsinline:!0});Z.muted=!0;let $=G("div",{className:"fig-fill-picker-webcam-status",role:"status","aria-live":"polite"},G("span",{},"Camera access required")),X=G("fig-video",{className:"fig-fill-picker-webcam-preview","aria-label":"Webcam preview","aspect-ratio":"1/1",fit:"cover",checkerboard:"true",autoplay:"true",muted:"true"},[Z,$]),Y=G("div",{className:"fig-fill-picker-webcam-controls"},G("fig-button",{className:"fig-fill-picker-webcam-capture",variant:"secondary",full:!0,disabled:!0},"Capture"));J.replaceChildren(Q,X,Y),this.#UQ(J)}#UQ(J){let Q=J.querySelector(".fig-fill-picker-webcam-video"),Z=J.querySelector(".fig-fill-picker-webcam-status"),$=J.querySelector(".fig-fill-picker-webcam-capture"),X=J.querySelector(".fig-fill-picker-webcam-camera"),Y=J.querySelector(".fig-fill-picker-camera-select"),j=(W)=>{if(W)$.removeAttribute("disabled");else $.setAttribute("disabled","")},K=()=>{let W=!!this.#Z.stream&&Q.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&Q.videoWidth>0&&Q.videoHeight>0;if(j(W),W)Z.querySelector("span").textContent="Camera ready",Z.style.display="none",this.#GJ(Q)};Q.addEventListener("loadedmetadata",K),Q.addEventListener("canplay",K),Q.addEventListener("playing",K);let U=(W)=>{this.#Z.stream=W,Q.srcObject=W,Q.muted=!0,Q.playsInline=!0,Q.style.display="block";let O=Q.play?.();if(O?.catch)O.catch(()=>{});K()},z=async(W,O)=>{let f=await navigator.mediaDevices.enumerateDevices();if(W!=null&&W!==this.#b)return;let H=f.filter((R)=>R.kind==="videoinput");if(H.length>1){X.style.display="";let R=Y.querySelector(":scope > fig-select-options");if(!R)R=document.createElement("fig-select-options"),Y.append(R);if(R.replaceChildren(),H.forEach((_,k)=>{let V=document.createElement("fig-select-option");V.value=_.deviceId;let q=_.label||(H.length>1?`Camera ${k+1}`:"Camera");V.textContent=q.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(M,D)=>{return` ${/^\d+$/.test(D)?Number.parseInt(D,10).toString():D.replace(/^0+/,"")||"0"}`}),R.append(V)}),O)Y.value=O}else X.style.display="none",Y.querySelector(":scope > fig-select-options")?.replaceChildren()},L=async(W=null)=>{let O=W||this.#Z.deviceId||null,f=this.#Z.stream,H=f?.getTracks?.().filter((_)=>_.readyState!=="ended")??[];if(f&&H.length){let _=f.getVideoTracks?.()?.[0]?.getSettings?.()?.deviceId||this.#Z.deviceId||null;if(!O||O===_){U(f),this.#P(),z(null,O||_);return}}this.#YJ({emit:Boolean(f)});let R=this.#b;j(!1),Z.querySelector("span").textContent="Starting camera",Z.style.display="flex";try{let _={video:O?{deviceId:{exact:O}}:!0},k=await navigator.mediaDevices.getUserMedia(_);if(R!==this.#b||!this.isConnected||this.#R!=="webcam"){k.getTracks().forEach((q)=>q.stop());return}let V=k.getVideoTracks?.()?.[0];this.#Z.deviceId=O||V?.getSettings?.()?.deviceId||null,this.#Z.live=this.#p()==="live",U(k),this.#P(),await z(R,O)}catch(_){if(R!==this.#b)return;console.error("Webcam error:",_.name,_.message);let k="Camera access denied";if(_.name==="NotAllowedError")k="Camera permission denied";else if(_.name==="NotFoundError")k="No camera found";else if(_.name==="NotReadableError")k="Camera in use by another app";else if(_.name==="OverconstrainedError")k="Camera constraints not supported";else if(!window.isSecureContext)k="Camera requires secure context";Z.replaceChildren();let V=document.createElement("span");V.textContent=k,Z.appendChild(V),Z.style.display="flex",Q.style.display="none",j(!1)}};this.#$J=L,Y.addEventListener("change",(W)=>{let O=typeof W.detail==="string"?W.detail:W.target?.value;if(!O||O===this.#Z.deviceId)return;L(O)}),$.addEventListener("click",async()=>{if(!this.#Z.stream)return;let W=await this.#OJ(Q);if(!W)return;this.#z.url=W,this.#Z.live=!1;let O=this.#J.querySelector(".fig-fill-picker-image-preview");if(O)this.#r(O);if(Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).some((H)=>H.dataset.tab==="image"))this.#VJ("image");else this.#G(),this.#O();this.#x()})}#SJ(J){let Q=J.h/360,Z=J.s/100,$=J.v/100,X,Y,j,K=Math.floor(Q*6),U=Q*6-K,z=$*(1-Z),L=$*(1-U*Z),W=$*(1-(1-U)*Z);switch(K%6){case 0:X=$,Y=W,j=z;break;case 1:X=L,Y=$,j=z;break;case 2:X=z,Y=$,j=W;break;case 3:X=z,Y=L,j=$;break;case 4:X=W,Y=z,j=$;break;case 5:X=$,Y=z,j=L;break}return{r:Math.round(X*255),g:Math.round(Y*255),b:Math.round(j*255)}}#QJ(J){let Q=J.r/255,Z=J.g/255,$=J.b/255,X=Math.max(Q,Z,$),Y=Math.min(Q,Z,$),j=X-Y,K=0,U=X===0?0:j/X,z=X;if(X!==Y){switch(X){case Q:K=(Z-$)/j+(Z<$?6:0);break;case Z:K=($-Q)/j+2;break;case $:K=(Q-Z)/j+4;break}K/=6}return{h:K*360,s:U*100,v:z*100,a:1}}#h(J){if(!J||typeof J.h!=="number"||typeof J.s!=="number"||typeof J.v!=="number")return"#D9D9D9";let Q=this.#SJ(J),Z=($)=>{return(isNaN($)?217:Math.max(0,Math.min(255,Math.round($)))).toString(16).padStart(2,"0")};return`#${Z(Q.r)}${Z(Q.g)}${Z(Q.b)}`}#ZJ(J){let Q=parseInt(J.slice(1,3),16),Z=parseInt(J.slice(3,5),16),$=parseInt(J.slice(5,7),16);return this.#QJ({r:Q,g:Z,b:$})}#zQ(J,Q=1){let Z=parseInt(J.slice(1,3),16),$=parseInt(J.slice(3,5),16),X=parseInt(J.slice(5,7),16);return`rgba(${Z}, ${$}, ${X}, ${Q})`}#OQ(J){let Q=Math.max(0,Math.min(1,Number(J)||0)),Z=Math.round(Q*1000)/1000;return String(Z)}#GQ(J=this.#$){let Q=this.#SJ(J);return`rgba(${Q.r}, ${Q.g}, ${Q.b}, ${this.#OQ(J.a)})`}#LQ(J){let Q=String(J??"").trim();if(!Q)return null;let Z=Q.match(/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(Z){let X=Z[1];if(X.length===3)X=X[0]+X[0]+X[1]+X[1]+X[2]+X[2];let Y=1;if(X.length===8)Y=parseInt(X.slice(6,8),16)/255,X=X.slice(0,6);return{...this.#ZJ(`#${X}`),a:Y}}let $=Q.match(/^rgba?\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))(?:\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*)?\)$/i);if($){let X=Math.max(0,Math.min(255,Math.round(parseFloat($[1])))),Y=Math.max(0,Math.min(255,Math.round(parseFloat($[2])))),j=Math.max(0,Math.min(255,Math.round(parseFloat($[3])))),K=$[4]!==void 0?Math.max(0,Math.min(1,parseFloat($[4]))):1;if(![X,Y,j,K].every(Number.isFinite))return null;return{...this.#QJ({r:X,g:Y,b:j}),a:K}}return null}#VQ(J,Q=1){let Z=+(parseInt(J.slice(1,3),16)/255).toFixed(4),$=+(parseInt(J.slice(3,5),16)/255).toFixed(4),X=+(parseInt(J.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${Z} ${$} ${X} / ${Q})`}#fQ(J){let Q=J.r/255,Z=J.g/255,$=J.b/255,X=Math.max(Q,Z,$),Y=Math.min(Q,Z,$),j,K,U=(X+Y)/2;if(X===Y)j=K=0;else{let z=X-Y;switch(K=U>0.5?z/(2-X-Y):z/(X+Y),X){case Q:j=((Z-$)/z+(Z<$?6:0))/6;break;case Z:j=(($-Q)/z+2)/6;break;case $:j=((Q-Z)/z+4)/6;break}}return{h:j*360,s:K*100,l:U*100}}#qQ(J){let Q=J.h/360,Z=J.s/100,$=J.l/100,X,Y,j;if(Z===0)X=Y=j=$;else{let K=(L,W,O)=>{if(O<0)O+=1;if(O>1)O-=1;if(O<0.16666666666666666)return L+(W-L)*6*O;if(O<0.5)return W;if(O<0.6666666666666666)return L+(W-L)*(0.6666666666666666-O)*6;return L},U=$<0.5?$*(1+Z):$+Z-$*Z,z=2*$-U;X=K(z,U,Q+0.3333333333333333),Y=K(z,U,Q),j=K(z,U,Q-0.3333333333333333)}return{r:Math.round(X*255),g:Math.round(Y*255),b:Math.round(j*255)}}#cJ(J){let Q=(W)=>{return W=W/255,W<=0.04045?W/12.92:Math.pow((W+0.055)/1.055,2.4)},Z=Q(J.r),$=Q(J.g),X=Q(J.b),Y=0.4122214708*Z+0.5363325363*$+0.0514459929*X,j=0.2119034982*Z+0.6806995451*$+0.1073969566*X,K=0.0883024619*Z+0.2817188376*$+0.6299787005*X,U=Math.cbrt(Y),z=Math.cbrt(j),L=Math.cbrt(K);return{l:0.2104542553*U+0.793617785*z-0.0040720468*L,a:1.9779984951*U-2.428592205*z+0.4505937099*L,b:0.0259040371*U+0.7827717662*z-0.808675766*L}}#HQ(J){let Q=this.#cJ(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}}#dJ(J){let Q=J.l+0.3963377774*J.a+0.2158037573*J.b,Z=J.l-0.1055613458*J.a-0.0638541728*J.b,$=J.l-0.0894841775*J.a-1.291485548*J.b,X=Q*Q*Q,Y=Z*Z*Z,j=$*$*$,K=(U)=>{let z=U<=0.0031308?12.92*U:1.055*Math.pow(U,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,z))*255)};return{r:K(4.0767416621*X-3.3077115913*Y+0.2309699292*j),g:K(-1.2684380046*X+2.6097574011*Y-0.3413193965*j),b:K(-0.0041960863*X-0.7034186147*Y+1.707614701*j)}}#BQ(J){let Q=J.h*Math.PI/180;return this.#dJ({l:J.l,a:J.c*Math.cos(Q),b:J.c*Math.sin(Q)})}#O(){if(this.#A())return;this.#G(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#x(){if(this.#A())return;this.#E=JSON.stringify(this.value),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let J={type:this.#U,colorSpace:this.#k};switch(this.#U){case"solid":return{...J,color:this.#h(this.#$),alpha:this.#$.a,hsv:{...this.#$}};case"gradient":return{...J,gradient:P(this.#Q),css:this.#hJ()};case"image":return{...J,image:{...this.#z}};case"video":return{...J,video:this.#HJ()};case"webcam":return{...J,webcam:this.#qJ()};default:return{...J,...this.#u[this.#U]}}}set value(J){if(typeof J==="string")this.setAttribute("value",J);else this.setAttribute("value",JSON.stringify(J))}attributeChangedCallback(J,Q,Z){if(Q===Z)return;switch(J){case"value":if(this.#a(),this.#G(),this.#J?.open&&!this.#D)this.#sJ(),this.#E=JSON.stringify(this.value);break;case"disabled":if(this.#S(),this.#A()&&this.#J?.open)this.close();break;case"alpha":case"mode":{if(!this.#J)break;let $=this.#J.open;if(this.#IJ(),$&&this.isConnected)this.#s();break}case"webcam-mode":if(this.#U==="webcam")this.#G();break;case"default-video":if(this.#U==="video")this.#fJ({emit:!1}),this.#G();break;case"aria-label":if(this.#J)this.#J.setAttribute("aria-label",this.#n());case"aria-labelledby":case"aria-describedby":this.#S();break}}}A("fig-fill-picker",y);class B extends HTMLElement{static#K=new Set(["oklch","hsl"]);static#Y=10;static#j=10;static#W=8;static#J=3;static#_=210;static#R={type:"linear",angle:135,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{color:"#FF0000",position:0,opacity:100},{color:"#4F9EFF",position:100,opacity:100}]};#U=!1;#k=null;#$=null;#L={...B.#R};static get observedAttributes(){return["value"]}get value(){return{type:"gradient",gradient:{...this.#L}}}set value(J){if(J==null||J===""){this.removeAttribute("value");return}if(typeof J==="string"){this.setAttribute("value",J);return}this.setAttribute("value",JSON.stringify(J))}connectedCallback(){this.#Q(),this.#z(),this.#D(),this.#T()}attributeChangedCallback(J,Q,Z){if(Q===Z)return;if(J!=="value")return;if(this.#z(),this.#U)this.#T()}#Q(){if(!(this.hasAttribute("aria-label")||this.hasAttribute("aria-labelledby"))&&!this.hasAttribute("aria-hidden"))this.setAttribute("aria-hidden","true")}#z(){let J=this.getAttribute("value");if(!J){this.#L={...B.#R,stops:B.#R.stops.map((Q)=>({...Q}))};return}try{let Q=JSON.parse(J),Z=Q?.type==="gradient"&&Q.gradient?Q.gradient:Q?.gradient?Q.gradient:Q;if(!Z||typeof Z!=="object")return;this.#L=this.#X({...B.#R,...Z})}catch{}}#X(J){let Q={...J??{}},Z=String(Q.interpolationSpace??"srgb").toLowerCase(),$=String(Q.hueInterpolation??"shorter").toLowerCase(),X=Array.isArray(Q.stops)?Q.stops.map((Y)=>({color:String(Y?.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:Y?.position??0,opacity:Y?.opacity??100})):B.#R.stops.map((Y)=>({...Y}));if(X.length<2)return{...B.#R,stops:B.#R.stops.map((Y)=>({...Y}))};return{type:["linear","radial","angular"].includes(Q.type)?Q.type:"linear",angle:Number.isFinite(Number(Q.angle))?Number(Q.angle):135,interpolationSpace:Z,hueInterpolation:$,stops:X}}#Z(){return B.#K.has(this.#L.interpolationSpace||"srgb")}#w(J){let{r:Q,g:Z,b:$}=i(J);if(this.#L.interpolationSpace==="hsl")return r(Q,Z,$).h;let X=l(Q,Z,$);return(o(X.l,X.a,X.b).h%360+360)%360}#F(){let J=this.#H(),Q=this.#w(J[0]?.color||"#FF0000"),Z=this.#w(J[J.length-1]?.color||"#4F9EFF"),$=B.#_-Q,Y=((B.#_-Z-$)%360+360)%360,j=Y===0?0:Y-360,K=this.#L.hueInterpolation||"shorter",U;if(K==="increasing")U=j;else if(K==="decreasing")U=Y;else if(K==="longer")U=Y<180?j:Y;else U=Y<=180?Y:j;let z=Math.sign(U),L=Math.asin(B.#J/2/B.#W)*180/Math.PI,W=Math.min(L,Math.max(0,(Math.abs(U)-0.01)/2));return{startDeg:$+z*W,sweepDeg:U-z*W*2}}#N(J){let Q=J*Math.PI/180;return{x:B.#Y+B.#W*Math.cos(Q),y:B.#j+B.#W*Math.sin(Q)}}#V(J,Q){let Z=J+Q,$=this.#N(J),X=this.#N(Z),Y=Math.abs(Q)>180?1:0,j=Q>=0?1:0;return`M ${$.x} ${$.y} A ${B.#W} ${B.#W} 0 ${Y} ${j} ${X.x} ${X.y}`}#u(){let J=this.#N(180),Q=this.#N(0);return`M ${J.x} ${J.y} L ${Q.x} ${Q.y}`}#q(J){let Q=B.#J,Z=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none"><path d="${J}" fill="none" stroke="white" stroke-width="${Q}" stroke-linecap="round" stroke-linejoin="round"/></svg>`;return`url("data:image/svg+xml,${encodeURIComponent(Z)}")`}#H(){return[...this.#L.stops].sort((J,Q)=>(J.position??0)-(Q.position??0))}#M(){let J=this.#L.interpolationSpace||"srgb";if(J==="srgb")return"";if(B.#K.has(J))return` in ${J} ${this.#L.hueInterpolation||"shorter"} hue`;return` in ${J}`}#f(){let J=this.#H(),Q=this.#M();if(this.#Z()){let $=(B.#_+90)%360,X=this.#L.interpolationSpace,Y=(K)=>X==="oklch"?`oklch(65% 0.25 ${K})`:`hsl(${K} 100% 50%)`,j=[0,300,240,180,120,60,0].map(Y).join(", ");return`conic-gradient(from ${$}deg in ${X} decreasing hue, ${j})`}let Z=J.map(($)=>`${$.color} ${$.position??0}%`).join(", ");return`linear-gradient(90deg${Q}, ${Z})`}#D(){if(this.#U)return;let J=B.#J,Q=u("svg",{className:"fig-interpolation-swatch-svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true"},u("circle",{className:"fig-interpolation-swatch-rim",cx:"10",cy:"10",r:"8",fill:"none",stroke:"currentColor","stroke-width":J})),Z=G("div",{className:"fig-interpolation-swatch-fill","aria-hidden":"true"});this.replaceChildren(Q,Z),this.#k=Q,this.#$=Z,this.#U=!0}#T(){if(!this.#$)return;let J=this.#Z();if(this.#k)this.#k.style.display=J?"":"none";let Q=J?(()=>{let{startDeg:$,sweepDeg:X}=this.#F();return this.#V($,X)})():this.#u(),Z=this.#q(Q);this.#$.style.setProperty("-webkit-mask-image",Z),this.#$.style.maskImage=Z,this.#$.style.background=this.#f()}}A("fig-interpolation-swatch",B);
|