@rogieking/figui3 8.9.16 → 8.9.17
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-editor/SKILL.md +8 -4
- package/.cursor/skills/figui3/SKILL.md +1 -1
- package/README.md +15 -5
- package/dist/fig-editor.js +3 -3
- package/dist/fig.js +6 -6
- package/fig-editor.js +344 -84
- package/fig.js +124 -21
- package/package.json +1 -1
|
@@ -136,20 +136,24 @@ Playground: `#fill-picker` — `all-modes`, `solid`, `gradient`, `image`, `video
|
|
|
136
136
|
| `alpha` | `"true"` default; hide alpha with `"false"` |
|
|
137
137
|
| `mode` | Lock modes: `solid`, `gradient`, `image`, `video`, `webcam`, comma-separated, plus custom names |
|
|
138
138
|
| `disabled` | Presence |
|
|
139
|
+
| `webcam-mode` | `live` (default) or `snapshot`. Webcam tab starts the camera. Capture writes a still and switches to Image |
|
|
140
|
+
| `default-video` | Sample clip URL when Video has no file |
|
|
139
141
|
|
|
140
|
-
Events: `input` / `change` with fill payload in `detail`.
|
|
142
|
+
Events: `input` / `change` with fill payload in `detail`. `webcamstream` with `{ stream, deviceId }`. Live camera is `webcamStream` / `releaseWebcam()`, never JSON.
|
|
141
143
|
|
|
142
144
|
Value shapes:
|
|
143
145
|
|
|
144
146
|
```txt
|
|
145
147
|
solid { type, colorSpace, color, alpha, hsv }
|
|
146
148
|
gradient { type, colorSpace, gradient, css }
|
|
147
|
-
image { type, colorSpace, image }
|
|
148
|
-
video { type, colorSpace, video }
|
|
149
|
-
webcam { type, colorSpace,
|
|
149
|
+
image { type, colorSpace, image: { url, scaleMode, scale } } // scaleMode includes tile
|
|
150
|
+
video { type, colorSpace, video: { url, poster, scaleMode, scale, opacity } } // fill | fit | crop
|
|
151
|
+
webcam { type, colorSpace, webcam: { live, snapshot, deviceId, scaleMode, scale, opacity } }
|
|
150
152
|
custom { type: <modeName>, ...payload }
|
|
151
153
|
```
|
|
152
154
|
|
|
155
|
+
Legacy `{ type: "webcam", image: { url } }` still parses as `webcam.snapshot` for one release. `fig-input-fill` uses the same `webcam` / `video.poster` shapes.
|
|
156
|
+
|
|
153
157
|
`fig-input-color` expects solid data (`detail.color`, optional `detail.alpha`). Keep legacy `value` / `hex` / `rgba` on color input events.
|
|
154
158
|
|
|
155
159
|
Do not use `picker` or `picker-anchor` on `fig-input-color`. Forward picker chrome with `picker-*` (e.g. `picker-dialog-position`).
|
|
@@ -138,7 +138,7 @@ Playground hashes: `/figui3#{id}`. Full attrs: [reference.md](reference.md).
|
|
|
138
138
|
| Tag | Playground | Notes |
|
|
139
139
|
|---|---|---|
|
|
140
140
|
| `fig-input-color` | (propkit `#color`) | Solid color. `text`, `alpha`. Auto-detects `fig-fill-picker` |
|
|
141
|
-
| `fig-input-fill` | `#fill-input` | Solid/gradient/image/video JSON `value`. `picker-*` forwarded if picker registered |
|
|
141
|
+
| `fig-input-fill` | `#fill-input` | Solid/gradient/image/video/webcam JSON `value`. Same `webcam` / `video.poster` shape as the picker. `webcam-mode`, `default-video`, `picker-*` forwarded if picker registered |
|
|
142
142
|
| `fig-input-palette` | (propkit `#palette`) | Multi-color. `fixed`, `open` |
|
|
143
143
|
| `fig-input-gradient` | (propkit `#gradient`) | Stops. `edit`, `mode="handle\|tip"` |
|
|
144
144
|
| `fig-swatch` | `#swatch` | `size`, `selected`, `alpha` |
|
package/README.md
CHANGED
|
@@ -939,7 +939,7 @@ Supported interpolation spaces: `srgb`, `srgb-linear`, `display-p3`, `oklab`, `o
|
|
|
939
939
|
|
|
940
940
|
`<fig-input-fill>` — [demo](https://rog.ie/figui3/#fill-input)
|
|
941
941
|
|
|
942
|
-
A comprehensive fill input supporting solid, gradient, image, and
|
|
942
|
+
A comprehensive fill input supporting solid, gradient, image, video, and webcam fills. Without the optional picker, it renders a passive preview.
|
|
943
943
|
|
|
944
944
|
| Attribute | Type | Default | Description |
|
|
945
945
|
|---|---|---|---|
|
|
@@ -947,16 +947,21 @@ A comprehensive fill input supporting solid, gradient, image, and video fills. W
|
|
|
947
947
|
| `disabled` | boolean | `false` | Disabled state |
|
|
948
948
|
| `mode` | string | — | Lock to a fill mode |
|
|
949
949
|
| `alpha` | boolean | `true` | Show alpha controls |
|
|
950
|
+
| `webcam-mode` | string | `live` | Forwarded to the picker: `live` or `snapshot` |
|
|
951
|
+
| `default-video` | string | — | Forwarded sample clip URL when Video has no file |
|
|
950
952
|
| `picker-*` | string | — | Forwarded to `<fig-fill-picker>` when the optional picker is registered |
|
|
951
953
|
|
|
952
954
|
Add `aria-label` to name the generated picker, hex field, and opacity field as one fill control group.
|
|
953
955
|
|
|
956
|
+
Solid `alpha` is 0–1 (canonical). `opacity` 0–100 is also emitted for compatibility. Gradient values include `css`. Webcam JSON is `{ type, webcam }` — never a live `MediaStream`. Read `webcamStream` or listen for `webcamstream`. Video swatches use `video.poster`, not the mp4 URL.
|
|
957
|
+
|
|
954
958
|
**Events:**
|
|
955
959
|
|
|
956
960
|
| Event | Detail |
|
|
957
961
|
|---|---|
|
|
958
|
-
| `input` | `{ type, color?, gradient?, image?, video?, css }` |
|
|
959
|
-
| `change` | `{ type, color?, gradient?, image?, video?, css }` |
|
|
962
|
+
| `input` | `{ type, color?, gradient?, image?, video?, webcam?, css }` |
|
|
963
|
+
| `change` | `{ type, color?, gradient?, image?, video?, webcam?, css }` |
|
|
964
|
+
| `webcamstream` | `{ stream, deviceId }` |
|
|
960
965
|
|
|
961
966
|
```html
|
|
962
967
|
<fig-input-fill value='{"type":"solid","color":"#FF5733","opacity":100}'></fig-input-fill>
|
|
@@ -976,13 +981,18 @@ Optional full fill picker dialog supporting solid, gradient, image, video, and w
|
|
|
976
981
|
| `disabled` | boolean | `false` | Disabled state |
|
|
977
982
|
| `alpha` | boolean | `true` | Show alpha controls |
|
|
978
983
|
| `mode` | string | — | Lock to mode: `"solid"`, `"gradient"`, `"image"`, `"video"`, `"webcam"` |
|
|
984
|
+
| `webcam-mode` | string | `live` | `live` keeps the camera after close; Capture always writes an image still |
|
|
985
|
+
| `default-video` | string | — | Sample clip URL when Video is selected with no file |
|
|
986
|
+
|
|
987
|
+
Webcam JSON is `{ type: "webcam", webcam: { live, snapshot, deviceId, scaleMode, scale, opacity } }`. The live `MediaStream` is `webcamStream` / `webcamstream`, not `value`. Closing the dialog does not stop a live camera; call `releaseWebcam()` or disconnect the element. Capture in `live` mode only updates `webcam.snapshot`. Video JSON includes `poster`; the swatch paints that, never `url(file.mp4)`.
|
|
979
988
|
|
|
980
989
|
**Events:**
|
|
981
990
|
|
|
982
991
|
| Event | Detail |
|
|
983
992
|
|---|---|
|
|
984
|
-
| `input` | `{ type, gradient?, color?, css }` |
|
|
985
|
-
| `change` | `{ type, gradient?, color?, css }` |
|
|
993
|
+
| `input` | `{ type, gradient?, color?, image?, video?, webcam?, css }` |
|
|
994
|
+
| `change` | `{ type, gradient?, color?, image?, video?, webcam?, css }` |
|
|
995
|
+
| `webcamstream` | `{ stream, deviceId }` |
|
|
986
996
|
|
|
987
997
|
```html
|
|
988
998
|
<fig-fill-picker value='{"type":"solid","color":"#FF5733"}'>
|
package/dist/fig-editor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import"./fig.js";import"./fig-lab.js";function A(
|
|
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 c(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}function S(J){if(!J)return"";return`url("${String(J).replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}")`}function F(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 d(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 f(J,Q,Z){let $=document.createElement(J);return d($,Q),v($,Z)}var p="http://www.w3.org/2000/svg";function u(J,Q,Z){let $=document.createElementNS(p,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 s(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 i(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 O=j-K,L=U>0.5?O/(2-j-K):O/(j+K),W;switch(j){case $:W=((X-Y)/O+(X<Y?6:0))/6;break;case X:W=((Y-$)/O+2)/6;break;default:W=(($-X)/O+4)/6;break}return{h:W*360,s:L*100,l:U*100}}function I(J){let Q=J/255;return Q<=0.04045?Q/12.92:Math.pow((Q+0.055)/1.055,2.4)}function r(J,Q,Z){let $=I(J),X=I(Q),Y=I(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 l(J,Q,Z){return{l:J,c:Math.sqrt(Q*Q+Z*Z),h:Math.atan2(Z,Q)*180/Math.PI}}function o({owner:J,onStart:Q,onEnd:Z,startClass:$="",endClass:X="",chevronClass:Y="",startLabel:j="Scroll back",endLabel:K="Scroll forward"}={}){let U=(O,L)=>{let W=document.createElement("button");if(W.type="button",W.className=["fig-overflow",`fig-overflow-${O}`,O==="start"?$:X].filter(Boolean).join(" "),W.dataset.figOverflow=O,J)W.setAttribute(`data-fig-${J}-nav`,O);return W.setAttribute("tabindex","-1"),W.setAttribute("aria-label",O==="start"?j:K),W.appendChild(F("chevron",{size:"small",className:["fig-overflow-chevron",Y].filter(Boolean).join(" ")})),W.addEventListener("click",(z)=>{z.preventDefault(),z.stopPropagation(),L?.(z)}),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>$,O=!U||K<=$,L=!U||K+j>=Y-$;return J.classList.toggle("overflow-start",!O),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 n(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(),O=X?J.scrollLeft:J.scrollTop,L=(X?K.left-U.left:K.top-U.top)+O,W=X?K.width:K.height,z=Y-j,V=Math.max(0,Math.min(L+W/2-j/2,z));J.scrollTo({[X?"left":"top"]:V,behavior:$}),w(J,J,Z)})}function a(J){let Q=J||"";if(Q.startsWith("["))try{let $=JSON.parse(Q);return Array.isArray($)?$:[]}catch{}let Z=Q.includes(`
|
|
2
2
|
`)?`
|
|
3
|
-
`:",";return
|
|
3
|
+
`:",";return Q.split(Z).map(($)=>$.trim()).filter(Boolean)}function t(J){if(J&&typeof J==="object")return String(J.value??J.label??"");return String(J??"")}function e(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.#X()}attributeChangedCallback(J,Q,Z){if(Q===Z)return;if(J==="disabled")this.#X()}#X(){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 g extends HTMLElement{#X=null;#Y=null;#K=null;#W=this.syncOverflow.bind(this);connectedCallback(){if(!this.hasAttribute("slot"))this.setAttribute("slot","panel");this.#J(),this.#R(),this.#q(),this.addEventListener("scroll",this.#W,{passive:!0}),this.#K?.disconnect(),this.#K=new ResizeObserver(()=>this.syncOverflow()),this.#K.observe(this),requestAnimationFrame(()=>this.syncOverflow())}disconnectedCallback(){this.removeEventListener("scroll",this.#W),this.#K?.disconnect(),this.#K=null,this.#U()}syncOverflow(){return this.#R(),w(this,this,"y")}scrollToOption(J,Q="auto"){n(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()}#R(){let J=Array.from(this.children).find((Q)=>!Q.hasAttribute("data-fig-select-nav"));if(J?.tagName==="FIG-SEPARATOR")J.setAttribute("borderless","")}#q(){if(this.#X&&this.#Y&&this.contains(this.#X)&&this.contains(this.#Y))return;this.#U();let J=o({owner:"select",startLabel:"Scroll up",endLabel:"Scroll down",onStart:()=>b(this,"y",-1),onEnd:()=>b(this,"y",1)});this.#X=J.start,this.#Y=J.end,this.prepend(this.#X),this.append(this.#Y)}#U(){this.#X?.remove(),this.#Y?.remove(),this.#X=null,this.#Y=null,this.classList.remove("overflow-start","overflow-end")}}A("fig-select-options",g);class m extends HTMLElement{#X=null;#Y=null;#K=null;#W=null;#J=null;#R=null;#q=!1;#U=-1;#k=!1;#Z=!1;#G=null;#Q=!1;#z=null;#j=null;#$=!1;#I=this.#kJ.bind(this);#_=this.#GJ.bind(this);#F=this.#L.bind(this);#f=this.#KJ.bind(this);#H=this.#t.bind(this);#T=this.#jJ.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.#q)this.#x();if(this.#M(),this.#c(),this.#fJ(),this.#OJ(),this.#h(),this.#HJ(),this.#RJ(),this.open)this.#s()}disconnectedCallback(){this.#BJ(),document.removeEventListener("keydown",this.#f,!0),this.#R?.disconnect(),this.#R=null}attributeChangedCallback(J,Q,Z){if(Q===Z||!this.#q)return;if(J==="options"){this.#c(),this.#h();return}if(J==="value"||J==="label"){this.#h();return}if(J==="disabled"){this.#fJ();return}if(J==="open"){if(Z===null||Z==="false")this.#TJ();else this.#s();return}if(J==="position"||J==="offset"||J==="closedby")this.#OJ()}focus(J){this.#X?.focus(J)}blur(){this.#X?.blur()}#B(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")}#V(){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")}#C(){return Boolean(this.querySelector(":scope > fig-select-option:not([data-fig-generated]), :scope > fig-select-options > fig-select-option:not([data-fig-generated])"))}#A(){let J=this.#V();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.#C())return;let J=this.hasAttribute("options"),Q=J?this.#A():this.#V();if(!Q)return;this.#$=!0;try{for(let X of Q.querySelectorAll(":scope > fig-select-option[data-fig-generated]"))X.remove();if(!J)return;let Z=a(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",t(X)),Y.textContent=e(X),$)Q.insertBefore(Y,$);else Q.appendChild(Y)}}finally{this.#$=!1}}#x(){this.#q=!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,J){if(!customElements.get(j))
|
|
|
87
87
|
min-height: 0;
|
|
88
88
|
max-height: inherit;
|
|
89
89
|
}
|
|
90
|
-
`,j.appendChild(J);let Q=document.createElement("fig-button");Q.className="fig-select-trigger",Q.setAttribute("part","trigger"),Q.setAttribute("variant","ghost"),Q.setAttribute("aria-haspopup","listbox"),Q.setAttribute("aria-expanded","false");let Z=document.createElement("span");Z.className="fig-select-prepend",Z.setAttribute("part","prepend"),Z.setAttribute("aria-hidden","true");let $=document.createElement("span");$.className="fig-select-label",$.setAttribute("part","label"),Q.append(Z,$);let X=document.createElement("dialog",{is:"fig-popup"});if(X.setAttribute("is","fig-popup"),X.setAttribute("part","listbox"),X.setAttribute("theme","menu"),X.setAttribute("role","listbox"),"popover"in HTMLElement.prototype)X.setAttribute("popover","manual");X.id=m(),Q.setAttribute("aria-controls",X.id);let Y=document.createElement("slot");if(Y.setAttribute("name","panel"),X.appendChild(Y),j.append(Q,X),this.#Z=Q,this.#X=Z,this.#Y=$,this.#$=X,this.#j=Y,X.anchor=Q,this.#B(),this.#g(),!this.hasAttribute("value")){let W=this.#v().find((U)=>R(U,"selected"));if(W)this.setAttribute("value",W.value)}}#g(){if(!this.#$||this.#Q)return;if(typeof this.#$.positionPopup!=="function")return;this.#f=this.#$.positionPopup.bind(this.#$),this.#$.positionPopup=()=>{if(!this.open){this.#f?.();return}this.#Wj()},this.#Q=!0}#m(j){if(!j)return null;let J=document.createRange();J.selectNodeContents(j);let Q=[...J.getClientRects()].filter((Z)=>Z.width>0&&Z.height>0);if(Q.length)return Q[0];return j.getBoundingClientRect()}#i(){if(typeof this.#$?.parseViewportMargins==="function")return this.#$.parseViewportMargins();return{top:8,right:8,bottom:8,left:8}}#d(){let j=this.#Y?.getBoundingClientRect();if(!j)return null;return{x:j.x,y:j.y,width:j.width,height:j.height}}#c(){let j=window.visualViewport;return{width:j?.width??window.innerWidth,height:j?.height??window.innerHeight,offsetLeft:j?.offsetLeft??0,offsetTop:j?.offsetTop??0}}#w(j,J,Q=0.25){if(!j&&!J)return!1;if(!j||!J)return!0;return Math.abs(j.x-J.x)>Q||Math.abs(j.y-J.y)>Q||Math.abs(j.width-J.width)>Q||Math.abs(j.height-J.height)>Q}#y(j,J,Q=0.25){if(!j&&!J)return!1;if(!j||!J)return!0;return Math.abs(j.width-J.width)>Q||Math.abs(j.height-J.height)>Q||Math.abs(j.offsetLeft-J.offsetLeft)>Q||Math.abs(j.offsetTop-J.offsetTop)>Q}#Oj(){if(!this.#J)return!1;let j=this.#w(this.#W,this.#d()),J=this.#y(this.#O,this.#c());return!j&&!J}#Yj(){this.#W=this.#d(),this.#O=this.#c()}#Wj(){if(this.#Oj())return;let j=this.#$,J=this.#Y;if(!j||!J){this.#f?.();return}let Q=this.#v(),Z=Q.find((H)=>this.#U(H)===this.value)||Q[0];if(!Z){this.#f?.();return}this.#f?.();let $=j.getBoundingClientRect(),X=J.getBoundingClientRect(),Y=this.#m(Z);if(!$.width||!$.height||!X.width||!Y)return;let W=Y.left-$.left,U=Y.top-$.top,O=R(this,"full")?this.getBoundingClientRect().left:X.left-W,z=X.top-U,f=this.#i();if(typeof j.clampToViewport==="function")({left:O,top:z}=j.clampToViewport({left:O,top:z},$,f));else{let{left:H,top:_}=f,y=window.innerWidth-$.width-f.right,G=window.innerHeight-$.height-f.bottom;O=Math.min(Math.max(O,H),Math.max(H,y)),z=Math.min(Math.max(z,_),Math.max(_,G))}j.style.setProperty("right","auto","important"),j.style.setProperty("bottom","auto","important"),j.style.setProperty("left",`${Math.round(O)}px`,"important"),j.style.setProperty("top",`${Math.round(z)}px`,"important");let L=this.#R(),k=this.#m(Z);if(k&&L&&L.scrollHeight>L.clientHeight+1){let H=k.top-X.top;if(Math.abs(H)>0.5)L.scrollTop+=H;L.syncOverflow?.()}if(this.#J||this.open)this.#Yj()}#r(){this.#Z?.addEventListener("click",this.#V),this.#Z?.addEventListener("keydown",this.#G),this.addEventListener("click",this.#I),this.addEventListener("pointerover",this.#L),this.#$?.addEventListener("keydown",this.#G),this.#$?.addEventListener("close",this.#M),this.#j?.addEventListener("slotchange",this.#H)}#E(){this.#Z?.removeEventListener("click",this.#V),this.#Z?.removeEventListener("keydown",this.#G),this.removeEventListener("click",this.#I),this.removeEventListener("pointerover",this.#L),this.#$?.removeEventListener("keydown",this.#G),this.#$?.removeEventListener("close",this.#M),this.#j?.removeEventListener("slotchange",this.#H)}#Gj(){this.#B(),this.#F()}#Lj(){if(this.#_)return;this.#_=new MutationObserver((j)=>{if(this.#T||this.#q)return;let J=!1;for(let Q of j){if(Q.type==="childList"){if([...Q.addedNodes].some((Z)=>this.#N(Z))||[...Q.removedNodes].some((Z)=>this.#N(Z))||Q.target?.closest?.("fig-select-option"))J=!0}if(Q.type==="attributes"&&Q.target?.tagName==="FIG-SELECT-OPTION"){if(Q.attributeName==="value"||Q.attributeName==="disabled"||Q.attributeName==="label")J=!0;else if(Q.attributeName==="selected"){if(R(Q.target,"selected")){let Z=this.#U(Q.target);if((this.getAttribute("value")??"")!==Z)this.setAttribute("value",Z),J=!0}else if(this.#U(Q.target)===(this.getAttribute("value")??""))J=!0}}if(Q.type==="characterData"&&Q.target?.parentElement?.tagName==="FIG-SELECT-OPTION")J=!0}if(J)this.#F()}),this.#_.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","disabled","selected","label"]})}#v({enabledOnly:j=!1}={}){let J=this.#R(),Q=J?Array.from(J.querySelectorAll(":scope > fig-select-option")):[];if(!j)return Q;return Q.filter((Z)=>!R(Z,"disabled"))}#U(j){if(!j)return"";if(typeof j.value==="string")return j.value;let J=j.getAttribute?.("value");if(J!=null)return J;return(j.textContent||"").trim()}#Kj(j){if(!j)return"";let J=j.getAttribute?.("label");if(J!=null&&J!=="")return J.trim();let Q=[];for(let Z of j.childNodes){if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)Q.push(Y);continue}if(!(Z instanceof Element))continue;let $=Z.getAttribute("slot");if($==="prepend"||$==="append")continue;let X=Z.textContent?.trim();if(X)Q.push(X)}if(Q.length)return Q.join(" ").trim();return(j.textContent||"").trim()}#l(j){if(!this.#X)return;let J=j?.querySelector?.(':scope > [slot="prepend"]');this.#X.replaceChildren(...Array.from(J?.childNodes??[],(Q)=>Q.cloneNode(!0)))}#zj(){if(!this.#$)return;this.#$.setAttribute("position",this.getAttribute("position")||"bottom left");let j=this.getAttribute("offset");if(j)this.#$.setAttribute("offset",j);else this.#$.removeAttribute("offset");let J=this.getAttribute("closedby");if(J)this.#$.setAttribute("closedby",J);else this.#$.removeAttribute("closedby")}#Qj(){let j=R(this,"disabled");if(this.#Z)if(j)this.#Z.setAttribute("disabled","");else this.#Z.removeAttribute("disabled");if(j&&this.open)this.open=!1}#o(j){if(!j.length)return null;let J=j.find((Q)=>R(Q,"selected"));if(J&&!R(J,"disabled"))return J;return j.find((Q)=>!R(Q,"disabled"))||j[0]||null}#Uj(j){this.dispatchEvent(new CustomEvent("input",{detail:j,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:j,bubbles:!0,composed:!0}))}#F(){if(this.#T)return;this.#T=!0;try{let j=this.#v(),J=this.hasAttribute("value"),Q=J?this.getAttribute("value"):null,Z=J?j.find((W)=>this.#U(W)===Q):null,$=!1;if(!Z){if(J){if(!j.length){if(this.#Y)this.#Y.textContent=Q||this.getAttribute("label")||"";return}if(Z=this.#o(j),Z){let W=this.#U(Z);if(Q!==W)this.setAttribute("value",W),$=!0}else this.removeAttribute("value"),$=!0}else if(Z=j.find((W)=>R(W,"selected")),Z)this.setAttribute("value",this.#U(Z)),$=!0}for(let W of j){let U=W===Z;if(W.setAttribute("aria-selected",U?"true":"false"),U)W.setAttribute("selected","");else W.removeAttribute("selected")}let X=Z&&this.#Kj(Z)||this.getAttribute("label")||"";if(this.#Y)this.#Y.textContent=X;this.#l(Z);let Y=this.getAttribute("label")||"Select";if(this.#Z?.setAttribute("aria-label",Y),this.#R()?.syncOverflow?.(),$)this.#Uj(this.getAttribute("value")??"")}finally{this.#T=!1}}#kj(j){if(R(this,"disabled"))return;j.preventDefault(),j.stopPropagation();let J=!this.open;if(J&&this.#$&&this.#Z)this.#$.anchor=this.#Z;this.open=J}#Vj(j){let Q=(typeof j.composedPath==="function"?j.composedPath():[]).find((Z)=>Z?.tagName==="FIG-SELECT-OPTION");if(!Q||!this.contains(Q))return;if(R(Q,"disabled"))return;this.#n(Q)}#Nj(j){let Q=(typeof j.composedPath==="function"?j.composedPath():[]).find((Z)=>Z?.tagName==="FIG-SELECT-OPTION");if(!Q||!this.contains(Q))return;if(R(Q,"disabled"))return;if(j.relatedTarget instanceof Node&&Q.contains(j.relatedTarget))return;this.dispatchEvent(new CustomEvent("optionhover",{detail:this.#U(Q),bubbles:!0,composed:!0}))}#b(j){if(j.currentTarget===document&&j.key!=="Escape")return;if(!(this.open&&(this.#$?.matches?.(":open")??!1))){if(this.#Z?.contains(j.target)&&(j.key==="ArrowDown"||j.key==="Enter"||j.key===" ")){if(j.preventDefault(),this.#$&&this.#Z)this.#$.anchor=this.#Z;this.open=!0,requestAnimationFrame(()=>{let $=this.#v({enabledOnly:!0}).findIndex((X)=>this.#U(X)===this.value);this.#A($>=0?$:0)})}return}let Q=this.#v({enabledOnly:!0});if(!Q.length)return;switch(j.key){case"ArrowDown":j.preventDefault(),this.#a(),this.#A(this.#K+1);break;case"ArrowUp":j.preventDefault(),this.#a(),this.#A(this.#K-1);break;case"Home":j.preventDefault(),this.#A(0);break;case"End":j.preventDefault(),this.#A(Q.length-1);break;case"Escape":j.preventDefault(),this.open=!1,this.#Z?.focus();break;case"Enter":case" ":{this.#a();let Z=Q[this.#K];if(!Z)return;j.preventDefault(),this.#n(Z);break}}}#D(){if(this.hasAttribute("open"))this.removeAttribute("open");this.#Z?.setAttribute("aria-expanded","false"),this.#Z?.focus(),this.#K=-1}#n(j){let J=this.#U(j);this.setAttribute("value",J),this.#F(),this.#Uj(J),this.open=!1}#p(){return this.#v({enabledOnly:!0})}#a(){let j=this.#p();if(!j.length){this.#K=-1;return}let J=j.find((Z)=>Z===document.activeElement),Q=J?j.indexOf(J):-1;this.#K=Q>=0?Q:this.#K}#A(j){let J=this.#p();if(!J.length)return;let Q=(j%J.length+J.length)%J.length;this.#K=Q,J[Q]?.focus()}#qj(){if(!this.#$||!this.#Z)return;let j=Math.ceil(this.getBoundingClientRect().width),J=Math.ceil(this.#Z.getBoundingClientRect().width),Q=Math.max(j,J,96);this.#$.style.setProperty("width","max-content","important"),this.#$.style.setProperty("min-width",`${Q}px`,"important"),this.#$.style.setProperty("max-width","min(20rem, calc(100vw - 1rem))","important")}#fj(){if(!this.#$||R(this,"disabled"))return;if(this.#Z)this.#$.anchor=this.#Z;this.#g(),this.#J=!1,this.#W=null,this.#O=null,this.#F(),this.#qj(),this.#$.open=!0,document.addEventListener("keydown",this.#G,!0),this.#Z?.setAttribute("aria-expanded","true"),this.#K=-1,requestAnimationFrame(()=>{this.#qj(),this.#Wj();let j=this.#R(),Q=this.#p().findIndex((Z)=>this.#U(Z)===this.value);if(Q>=0)this.#A(Q);else if(this.#Z?.hasAttribute("data-focus-visible")||this.#Z?.matches?.(":focus-visible"))this.#A(0);j?.syncOverflow?.(),this.#J=!0,this.#Yj()})}#Hj(){if(!this.#$)return;this.#J=!1,this.#W=null,this.#O=null,document.removeEventListener("keydown",this.#G,!0),this.#$.open=!1,this.#Z?.setAttribute("aria-expanded","false")}}A("fig-select",h);var e=["srgb","srgb-linear","display-p3","oklab","oklch","hsl"],jj=["shorter","longer","increasing","decreasing"],E=new Set(["oklch","hsl"]);function M(j){let J={...j??{}},Q=String(J.interpolationSpace??"srgb").toLowerCase();if(!e.includes(Q))Q="srgb";J.interpolationSpace=Q;let Z=String(J.hueInterpolation??"shorter").toLowerCase();return J.hueInterpolation=jj.includes(Z)?Z:"shorter",J}function P(j){let J=M(j),Q={...J,interpolationSpace:J.interpolationSpace};if(E.has(J.interpolationSpace))Q.hueInterpolation=J.hueInterpolation;else delete Q.hueInterpolation;return Q}function Jj(j){let J=M(j);if(J.interpolationSpace==="srgb")return"";if(E.has(J.interpolationSpace))return`in ${J.interpolationSpace} ${J.hueInterpolation} hue`;return`in ${J.interpolationSpace}`}function I(j){let J=M(j);if(E.has(J.interpolationSpace))return`${J.interpolationSpace}-${J.hueInterpolation||"shorter"}`;return J.interpolationSpace}function C(j){let J=String(j??"");for(let Q of E){let Z=`${Q}-`;if(J.startsWith(Z))return{interpolationSpace:Q,hueInterpolation:J.slice(Z.length)||"shorter"}}return{interpolationSpace:J||"srgb",hueInterpolation:"shorter"}}var Qj=0;class N extends HTMLElement{static#Z=[{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#$(j){let J=N.#Z,Q=J.find((W)=>W.value===j);if(Q)return Q;let Z=C(j),$=J.find((W)=>W.space===Z.interpolationSpace),X=$?.subtitle.split(" ")[0]??Z.interpolationSpace.toUpperCase(),Y=Z.hueInterpolation;return{value:j,space:Z.interpolationSpace,title:$?.title??"Custom",subtitle:E.has(Z.interpolationSpace)?`${X} ${Y.charAt(0).toUpperCase()}${Y.slice(1)}`:X}}#X=null;#Y=null;#j=null;#_=`fig-fill-picker-dialog-${++Qj}`;#k="solid";anchorElement=null;#K="solid";#T="srgb";#Q={h:0,s:0,v:85,a:1};#f="hex";#J={type:"linear",angle:0,centerX:50,centerY:50,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{position:0,color:"#D9D9D9",opacity:100},{position:100,color:"#737373",opacity:100}]};#W={url:null,scaleMode:"fill",scale:50};#O={url:null,scaleMode:"fill",scale:50};#q={stream:null,snapshot:null};#V={};#I={};#L=null;#G=null;#M=null;#H=null;#N=!1;#B=!1;#R=null;#x=null;#u=null;#C=null;#Jj=null;#g=0;#m=null;#i=null;#d=new Set;#c=new Set;constructor(){super();this.#m=this.#Gj.bind(this),this.#i=this.#Lj.bind(this)}static get observedAttributes(){return["value","disabled","alpha","mode","aria-label","aria-labelledby","aria-describedby"]}connectedCallback(){this.style.display="contents",this.#y(()=>{this.#Wj(),this.#v(),this.#U()})}disconnectedCallback(){if(this.#Qj(),this.#Oj(),this.#Yj(),this.#Y)this.#Y.removeAttribute("selected");if(this.#X)this.#X.removeEventListener("click",this.#m),this.#X.removeEventListener("keydown",this.#i);this.#X=null,this.#Y=null}#w(){return this.hasAttribute("disabled")&&this.getAttribute("disabled")!=="false"}#y(j){let J=requestAnimationFrame(()=>{if(this.#d.delete(J),this.isConnected)j()});return this.#d.add(J),J}#Oj(){this.#d.forEach((j)=>cancelAnimationFrame(j)),this.#d.clear()}#Yj(){if(this.#c.forEach((j)=>URL.revokeObjectURL(j)),this.#c.clear(),this.#q.snapshot?.startsWith("blob:")){if(this.#W.url===this.#q.snapshot)this.#W.url=null;this.#q.snapshot=null}}#Wj(){let j=Array.from(this.children).find((J)=>!J.getAttribute("slot")?.startsWith("mode-"));if(!j)this.#Y=document.createElement("fig-swatch"),this.#Y.setAttribute("background","#D9D9D9"),this.appendChild(this.#Y),this.#X=this.#Y;else if(j.matches("fig-swatch, fig-chit"))this.#Y=j,this.#X=j;else this.#X=j,this.#Y=null;if(this.#E(),this.#X.removeEventListener("click",this.#m),this.#X.addEventListener("click",this.#m),this.#X.removeEventListener("keydown",this.#i),this.#X.addEventListener("keydown",this.#i),this.#Y)this.#y(()=>{let J=this.#Y.querySelector('input[type="color"]');if(J)J.remove();this.#E()})}#r(){return this.getAttribute("aria-label")||"Fill picker"}#E(){if(!this.#X)return;let j=this.#w(),J=this.getAttribute("aria-labelledby");if(!this.#X.hasAttribute("role"))this.#X.setAttribute("role","button");if(this.#X.setAttribute("tabindex",j?"-1":"0"),this.#X.setAttribute("aria-disabled",j?"true":"false"),this.#X.setAttribute("aria-haspopup","dialog"),this.#X.setAttribute("aria-expanded",this.#j?.open?"true":"false"),this.#X.setAttribute("aria-controls",this.#_),this.#X.removeAttribute("aria-hidden"),J)this.#X.setAttribute("aria-labelledby",J),this.#X.removeAttribute("aria-label");else if(this.hasAttribute("aria-label"))this.#X.setAttribute("aria-label",`Open ${this.#r()}`),this.#X.removeAttribute("aria-labelledby");else if(this.#X.removeAttribute("aria-labelledby"),!this.#X.hasAttribute("aria-label"))this.#X.setAttribute("aria-label",`Open ${this.#r()}`);let Q=this.getAttribute("aria-describedby");if(Q)this.#X.setAttribute("aria-describedby",Q);else this.#X.removeAttribute("aria-describedby")}#Gj(j){if(this.#w())return;j.stopPropagation(),j.preventDefault(),this.#l()}#Lj(j){if(j.key!=="Enter"&&j.key!==" ")return;if(this.#w())return;j.preventDefault(),j.stopPropagation(),this.#l()}#v(){let j=this.getAttribute("value");if(!j)return;let J=["solid","gradient","image","video","webcam"];try{let Q=JSON.parse(j);if(Q.type)this.#K=Q.type;if(Q.color){if(typeof Q.color==="string")this.#Q=this.#jj(Q.color);else if(typeof Q.color==="object"&&Q.color.h!==void 0)this.#Q=Q.color}let Z=Q.alpha!==void 0?Number(Q.alpha):Q.opacity!==void 0?Number(Q.opacity)/100:void 0;if(Number.isFinite(Z))this.#Q.a=Math.max(0,Math.min(1,Z));if(this.#T="srgb",Q.gradient)this.#J=M({...this.#J,...Q.gradient});if(Q.image)this.#W={...this.#W,...Q.image};if(Q.video)this.#O={...this.#O,...Q.video};if(Q.type&&!J.includes(Q.type)){let{type:$,...X}=Q;this.#I[Q.type]=X}}catch(Q){if(j.startsWith("#"))this.#K="solid",this.#Q=this.#jj(j)}}#U(){if(!this.#Y)return;let j,J="cover",Q="center";switch(this.#K){case"solid":j=this.#h(this.#Q);break;case"gradient":j=this.#Cj();break;case"image":if(this.#W.url){j=`url(${this.#W.url})`;let $=this.#Kj(this.#W.scaleMode,this.#W.scale);J=$.size,Q=$.position}else j="";break;case"video":if(this.#O.url){j=`url(${this.#O.url})`;let $=this.#Kj(this.#O.scaleMode,this.#O.scale);J=$.size,Q=$.position}else j="";break;case"webcam":j=this.#q.snapshot?`url(${this.#q.snapshot})`:"";break;default:j=this.#V[this.#K]?.element?.getAttribute("swatch-background")||"#D9D9D9"}if(this.#Y.setAttribute("background",j),this.#Y.style.setProperty("--swatch-bg-size",J),this.#Y.style.setProperty("--swatch-bg-position",Q),this.#K==="solid")this.#Y.setAttribute("alpha",this.#Q.a);else this.#Y.removeAttribute("alpha")}#Kj(j,J){switch(j){case"fill":return{size:"cover",position:"center"};case"fit":return{size:"contain",position:"center"};case"crop":return{size:"cover",position:"center"};case"tile":return{size:`${J}%`,position:"top left"};default:return{size:"cover",position:"center"}}}#l(){if(this.#w())return;if(!this.#j)this.#Uj();if(this.#u=JSON.stringify(this.value),this.#C=this.#u,this.#F(this.#K,{emit:!1}),this.#Y)this.#Y.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.#b(),this.#D()})})}open(){this.#l()}close(){if(this.#j)this.#j.open=!1,this.#E()}#zj(){if(!this.#j)return;for(let[j,{element:J}]of Object.entries(this.#V)){let Q=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((Z)=>Z.dataset.tab===j);if(!Q)continue;while(Q.firstChild)J.appendChild(Q.firstChild)}}#Qj(){if(this.#R)this.#R(),this.#R=null;if(this.#x?.disconnect(),this.#x=null,this.#o(),!this.#j)return;this.#zj(),this.#j.remove(),this.#j=null,this.#Jj=null,this.#u=null,this.#C=null,this.#L=null,this.#G=null,this.#M=null,this.#H=null,this.#B=!1,this.#E()}#o(){if(this.#g+=1,this.#q.stream)this.#q.stream.getTracks().forEach((J)=>J.stop()),this.#q.stream=null;let j=this.#j?.querySelector(".fig-fill-picker-webcam-video");if(j)j.srcObject=null}#Uj(){this.#V={},this.querySelectorAll('[slot^="mode-"]').forEach((f)=>{let L=f.getAttribute("slot").slice(5);this.#V[L]={element:f,label:f.getAttribute("label")||L.charAt(0).toUpperCase()+L.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.#r()),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.#X;let j=this.getAttribute("dialog-position")||"left";this.#j.setAttribute("position",j),this.#j.setAttribute("offset",this.getAttribute("dialog-offset")||"8 8");let J=["solid","gradient","image","video","webcam"],Q={solid:"Solid",gradient:"Gradient",image:"Image",video:"Video",webcam:"Webcam"},Z=this.getAttribute("mode"),$;if(Z){if($=Z.split(",").map((L)=>L.trim().toLowerCase()).filter((L)=>J.includes(L)||this.#V[L]),$.length===0)$=[...J]}else $=[...J];let X={...Q};for(let[f,{label:L}]of Object.entries(this.#V))X[f]=L;if(!$.includes(this.#K))this.#K=$[0],this.#k=$[0];let Y;if($.length===1)Y=q("h3",{className:"fig-fill-picker-type-label"},X[$[0]]);else{let f=q("fig-select-options",{},$.map((L)=>q("fig-select-option",{value:L},X[L])));Y=q("fig-select",{className:"fig-fill-picker-type",label:"Fill type",value:this.#K},f)}let W=$.map((f)=>q("div",{className:"fig-fill-picker-tab","data-tab":f})),U=q("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-close","aria-label":"Close fill picker"},F("close"));this.#j.replaceChildren(q("fig-header",{},[Y,U]),q("fig-content",{},W)),document.body.appendChild(this.#j);for(let[f,{element:L}]of Object.entries(this.#V)){let k=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((H)=>H.dataset.tab===f);if(!k)continue;while(L.firstChild)k.appendChild(L.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:f,container:k}}))}let K=this.#j.querySelector(".fig-fill-picker-type");if(K)K.addEventListener("change",(f)=>{let L=typeof f.detail==="string"?f.detail:f.target?.value;if(L)this.#F(L)});this.#j.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#j.open=!1});let O=()=>{if(this.#Y)this.#Y.removeAttribute("selected");this.#o();let f=JSON.stringify(this.value);if(this.#C!==null&&this.#C!==f)this.#S();this.#u=null,this.#C=null,this.#E();let L=this.#X;this.#y(()=>{if(L?.isConnected)HTMLElement.prototype.focus.call(L)}),this.dispatchEvent(new CustomEvent("close"))};this.#j.addEventListener("close",O);let z={solid:()=>this.#Vj(),gradient:()=>this.#Pj(),image:()=>this.#hj(),video:()=>this.#dj(),webcam:()=>this.#pj()};for(let[f,L]of Object.entries(z))if(!this.#V[f]&&$.includes(f))L();for(let f of Object.keys(this.#V)){if(J.includes(f))continue;let L=Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).find((k)=>k.dataset.tab===f);if(!L)continue;L.addEventListener("input",(k)=>{if(k.target===this)return;if(k.stopPropagation(),k.detail)this.#I[f]=k.detail;this.#z()}),L.addEventListener("change",(k)=>{if(k.target===this)return;if(k.stopPropagation(),k.detail)this.#I[f]=k.detail;this.#S()})}}#F(j,{emit:J=!0}={}){let Q=Array.from(this.#j?.querySelectorAll(".fig-fill-picker-tab")??[]).find((W)=>W.dataset.tab===j);if(!Q)return;let Z=this.#k;if(this.#k=j,this.#K=j,Z==="webcam"&&j!=="webcam")this.#o();let $=this.#j.querySelector(".fig-fill-picker-type");if($&&$.value!==j)$.value=j;this.#j.querySelectorAll(".fig-fill-picker-tab").forEach((W)=>{if(W.dataset.tab===j)W.style.display="block";else W.style.display="none"});let Y=this.#j.querySelector("fig-content");if(Y)Y.style.padding=this.#V[j]?"0":"";if(j==="gradient")this.#y(()=>{this.#P();let W=Q.querySelector(".fig-fill-picker-gradient-bar-input");W?.refreshLayout?.(),this.#y(()=>{W?.refreshLayout?.()})});if(j==="webcam")this.#Jj?.();if(this.#U(),J)this.#z()}#kj(){if(!this.#j?.open)return;if(this.#F(this.#K,{emit:!1}),this.#b(),this.#D(),this.#t(),this.#M)this.#M.setAttribute("value",this.#Q.h);if(this.#H)this.#H.setAttribute("value",this.#Q.a*100),this.#H.setAttribute("color",this.#h(this.#Q));this.#P();let j=this.#j.querySelector('[data-tab="image"]'),J=j?.querySelector(".fig-fill-picker-scale-mode"),Q=j?.querySelector(".fig-fill-picker-scale"),Z=j?.querySelector(".fig-fill-picker-image-preview");if(J)J.value=this.#W.scaleMode;if(Q)Q.setAttribute("value",this.#W.scale),Q.style.display=this.#W.scaleMode==="tile"?"block":"none";if(Z)this.#s(Z);let $=this.#j.querySelector('[data-tab="video"]'),X=$?.querySelector(".fig-fill-picker-scale-mode"),Y=$?.querySelector(".fig-fill-picker-video-preview");if(X)X.value=this.#O.scaleMode;if(Y)this.#Xj(Y)}#Vj(){let j=this.#j.querySelector('[data-tab="solid"]'),J=this.getAttribute("alpha")!=="false",Q=q("canvas",{width:"200",height:"200"}),Z=q("fig-handle",{"aria-label":"Color saturation and brightness",role:"slider","aria-valuemin":"0","aria-valuemax":"100",type:"color",color:this.#h({...this.#Q,a:1}),"data-no-color-picker":!0,drag:!0,"drag-surface":".fig-fill-picker-color-area","drag-axes":"x,y","drag-snapping":"modifier"}),$=q("fig-preview",{className:"fig-fill-picker-color-area"},[Q,Z]),X=q("fig-tooltip",{text:"Sample color"},q("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-eyedropper","aria-label":"Sample color"},F("eyedropper"))),Y=q("div",{className:`fig-fill-picker-sliders${J?"":" is-hue-only"}`},[X,q("fig-slider",{type:"hue",variant:"classic",text:"false",min:"0",max:"360","aria-label":"Hue",value:this.#Q.h}),J?q("fig-slider",{type:"opacity",variant:"classic",text:"false",min:"0",max:"100","aria-label":"Opacity",value:this.#Q.a*100,color:this.#h(this.#Q)}):null]),W=q("fig-select-options",{},[["hex","Hex"],["rgb","RGB"],["css","CSS"],["hsl","HSL"],["hsb","HSB"],["lab","LAB"],["lch","LCH"]].map(([z,f])=>q("fig-select-option",{value:z},f))),U=q("fig-field",{className:"fig-fill-picker-inputs"},[q("fig-select",{className:"fig-fill-picker-input-mode",label:"Color value format",value:this.#f},W),q("span",{className:"fig-fill-picker-input-fields"})]);if(j.replaceChildren($,Y,U),this.#L=j.querySelector("canvas"),this.#G=j.querySelector("fig-handle"),this.#n(),this.#b(),this.#D(),this.#a(),this.#M=j.querySelector('fig-slider[type="hue"]'),this.#M.addEventListener("input",(z)=>{this.#Q.h=parseFloat(z.target.value),this.#b(),this.#D(),this.#t(),this.#z()}),this.#M.addEventListener("change",()=>{this.#S()}),J)this.#H=j.querySelector('fig-slider[type="opacity"]'),this.#H.addEventListener("input",(z)=>{this.#Q.a=parseFloat(z.target.value)/100,this.#t(),this.#z()}),this.#H.addEventListener("change",()=>{this.#S()});j.querySelector(".fig-fill-picker-input-mode").addEventListener("change",(z)=>{let f=typeof z.detail==="string"?z.detail:z.target?.value;if(!f)return;this.#f=f,this.#A()}),this.#A();let O=j.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)O.addEventListener("click",async()=>{try{let f=await new EyeDropper().open();this.#Q={...this.#jj(f.sRGBHex),a:this.#Q.a},this.#b(),this.#D(),this.#t(),this.#z()}catch(z){}});else O.setAttribute("disabled",""),O.title="EyeDropper not supported in this browser"}#Nj(){let j=this.#j?.querySelector('[data-tab="solid"]');if(j){let J=j.querySelector("canvas");if(J){let Q=document.createElement("canvas");Q.width=J.width,Q.height=J.height,J.replaceWith(Q),this.#L=Q,this.#a()}this.#b(),this.#D()}this.#$j(),this.#z()}#b(){if(!this.#L&&this.#j)this.#L=this.#j.querySelector('[data-tab="solid"] canvas');if(!this.#L)return;let j=this.#T==="display-p3"?"display-p3":"srgb",J=this.#L.getContext("2d",{colorSpace:j});if(!J)return;let Q=this.#L.width,Z=this.#L.height;J.clearRect(0,0,Q,Z);let $=this.#Q.h,X=this.#T==="display-p3",Y=J.createLinearGradient(0,0,Q,0);if(X){Y.addColorStop(0,"color(display-p3 1 1 1)");let[U,K,O]=hslToP3($,100,50);Y.addColorStop(1,`color(display-p3 ${U} ${K} ${O})`)}else Y.addColorStop(0,"#FFFFFF"),Y.addColorStop(1,`hsl(${$}, 100%, 50%)`);J.fillStyle=Y,J.fillRect(0,0,Q,Z);let W=J.createLinearGradient(0,0,0,Z);W.addColorStop(0,"rgba(0,0,0,0)"),W.addColorStop(1,"rgba(0,0,0,1)"),J.fillStyle=W,J.fillRect(0,0,Q,Z)}#D(j=0){if(!this.#G||!this.#L)return;this.#n();let J=this.#L.getBoundingClientRect();if((J.width===0||J.height===0)&&j<5){this.#y(()=>this.#D(j+1));return}let Q=Math.max(0,Math.min(100,this.#Q.s)),Z=Math.max(0,Math.min(100,100-this.#Q.v));this.#G.setAttribute("value",`${Q}% ${Z}%`),this.#G.setAttribute("color",this.#h({...this.#Q,a:1}))}#n(){if(!this.#G)return;this.#G.setAttribute("aria-valuenow",String(Math.round(this.#Q.v))),this.#G.setAttribute("aria-valuetext",`Saturation ${Math.round(this.#Q.s)}%, brightness ${Math.round(this.#Q.v)}%`),this.#G.removeAttribute("aria-pressed")}#p(j,J,Q={}){let{updateHandle:Z=!0,emitInput:$=!0,emitChange:X=!1}=Q;if(this.#Q.s=Math.max(0,Math.min(100,j*100)),this.#Q.v=Math.max(0,Math.min(100,(1-J)*100)),this.#G)this.#G.setAttribute("color",this.#h({...this.#Q,a:1})),this.#n();if(Z)this.#D();if(this.#t(),$)this.#z();if(X)this.#S()}#a(){if(this.#R)this.#R(),this.#R=null;if(!this.#L||!this.#G)return;let j=this.#L.parentElement||this.#L,J=this.#G,Q=!1,Z=(K,O={})=>{let z=j.getBoundingClientRect();if(z.width===0||z.height===0)return;let f=Math.max(0,Math.min(K.clientX-z.left,z.width)),L=Math.max(0,Math.min(K.clientY-z.top,z.height));this.#p(f/z.width,L/z.height,O)},$=(K)=>{if(K.button!==0)return;if(K.target===J||J.contains(K.target))return;Q=!0,this.#N=!0,j.setPointerCapture(K.pointerId),Z(K,{updateHandle:!0,emitInput:!0})},X=(K)=>{if(!Q)return;if(K.buttons===0){Y();return}Z(K,{updateHandle:!0,emitInput:!0})},Y=()=>{if(!Q)return;Q=!1,this.#N=!1,this.#S()},W=(K)=>{this.#N=!0;let O=K.detail?.px,z=K.detail?.py;if(!Number.isFinite(O)||!Number.isFinite(z))return;J.setAttribute("value",`${O*100}% ${z*100}%`),this.#p(O,z,{updateHandle:!1,emitInput:!0})},U=(K)=>{let O=K.detail?.px,z=K.detail?.py;if(Number.isFinite(O)&&Number.isFinite(z))J.setAttribute("value",`${O*100}% ${z*100}%`),this.#p(O,z,{updateHandle:!1,emitInput:!1});this.#N=!1,this.#S()};j.addEventListener("pointerdown",$),j.addEventListener("pointermove",X),j.addEventListener("pointerup",Y),j.addEventListener("pointercancel",Y),j.addEventListener("lostpointercapture",Y),J.addEventListener("input",W),J.addEventListener("change",U),this.#R=()=>{j.removeEventListener("pointerdown",$),j.removeEventListener("pointermove",X),j.removeEventListener("pointerup",Y),j.removeEventListener("pointercancel",Y),j.removeEventListener("lostpointercapture",Y),J.removeEventListener("input",W),J.removeEventListener("change",U),this.#N=!1}}#A(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let J=(W,U)=>q("fig-tooltip",{text:W},U),Q=(W,U,K,O,z,f)=>q("fig-input-number",{className:W,"aria-label":U,min:K,max:O,step:z,units:f}),Z=this.getAttribute("alpha")!=="false",$=()=>Z?J("Alpha",Q("fig-fill-picker-ci-a","Alpha",0,100,0.1,"%")):null,X=(W,U="")=>q("div",{className:["input-combo",U].filter(Boolean).join(" ")},W),Y;switch(this.#f){case"rgb":Y=X([J("Red",Q("fig-fill-picker-ci-r","Red",0,255)),J("Green",Q("fig-fill-picker-ci-g","Green",0,255)),J("Blue",Q("fig-fill-picker-ci-b","Blue",0,255)),$()]);break;case"hsl":Y=X([J("Hue",Q("fig-fill-picker-ci-h","Hue",0,360)),J("Saturation",Q("fig-fill-picker-ci-s","Saturation",0,100)),J("Lightness",Q("fig-fill-picker-ci-l","Lightness",0,100)),$()]);break;case"hsb":Y=X([J("Hue",Q("fig-fill-picker-ci-h","Hue",0,360)),J("Saturation",Q("fig-fill-picker-ci-s","Saturation",0,100)),J("Brightness",Q("fig-fill-picker-ci-v","Brightness",0,100)),$()]);break;case"lab":Y=X([J("Lightness",Q("fig-fill-picker-ci-okl","Lightness",0,100)),J("Green-Red axis",Q("fig-fill-picker-ci-oka","Green-Red axis",-0.4,0.4,0.001)),J("Blue-Yellow axis",Q("fig-fill-picker-ci-okb","Blue-Yellow axis",-0.4,0.4,0.001)),$()]);break;case"lch":Y=X([J("Lightness",Q("fig-fill-picker-ci-okl","Lightness",0,100)),J("Chroma",Q("fig-fill-picker-ci-okc","Chroma",0,0.4,0.001)),J("Hue",Q("fig-fill-picker-ci-okh","Hue",0,360)),$()]);break;case"css":Y=q("fig-input-text",{className:"fig-fill-picker-ci-css","aria-label":"CSS color",placeholder:"rgba(0, 0, 0, 1)"});break;default:{let W=q("fig-input-text",{className:"fig-fill-picker-ci-hex","aria-label":"Hex color",placeholder:"FFFFFF"});Y=Z?X([W,$()],"fig-fill-picker-ci-hex-row"):W}break}j.replaceChildren(Y),this.#qj(),this.#y(()=>this.#t())}#qj(){let j=this.#j?.querySelector(".fig-fill-picker-input-fields");if(!j)return;let J=()=>{if(this.#N)return;let $=this.#Hj();if(!$)return;let X=Number.isFinite($.a)?$.a:this.#Q.a;if(this.#Q={...$,a:X},this.#b(),this.#D(),this.#M)this.#M.setAttribute("value",this.#Q.h);if(this.#H&&Number.isFinite($.a))this.#H.setAttribute("value",this.#Q.a*100);this.#z()},Q=()=>this.#S();j.querySelectorAll("fig-input-number, fig-input-text").forEach(($)=>{$.addEventListener("input",J),$.addEventListener("change",Q)})}#fj(){let j=this.#j?.querySelector(".fig-fill-picker-ci-a");if(!j)return;let J=parseFloat(j.value);if(!Number.isFinite(J))return;return Math.max(0,Math.min(1,J/100))}#Hj(){let j=(Z)=>this.#j?.querySelector(`.${Z}`),J=(Z)=>parseFloat(j(Z)?.value??0),Q=(Z)=>{if(!Z)return null;let $=this.#fj();return{...Z,a:$??Z.a??this.#Q.a}};switch(this.#f){case"rgb":return Q(this.#e({r:J("fig-fill-picker-ci-r"),g:J("fig-fill-picker-ci-g"),b:J("fig-fill-picker-ci-b")}));case"hsl":{let Z=this.#tj({h:J("fig-fill-picker-ci-h"),s:J("fig-fill-picker-ci-s"),l:J("fig-fill-picker-ci-l")});return Q(this.#e(Z))}case"hsb":return Q({h:J("fig-fill-picker-ci-h"),s:J("fig-fill-picker-ci-s"),v:J("fig-fill-picker-ci-v")});case"lab":{let Z=this.#Aj({l:J("fig-fill-picker-ci-okl")/100,a:J("fig-fill-picker-ci-oka"),b:J("fig-fill-picker-ci-okb")});return Q(this.#e(Z))}case"lch":{let Z=this.#jJ({l:J("fig-fill-picker-ci-okl")/100,c:J("fig-fill-picker-ci-okc"),h:J("fig-fill-picker-ci-okh")});return Q(this.#e(Z))}case"css":{let Z=j("fig-fill-picker-ci-css");if(!Z)return null;return this.#oj(Z.value)}default:{let Z=j("fig-fill-picker-ci-hex");if(!Z)return null;let $=Z.value.replace(/^#/,"");if($.length===3)$=$[0]+$[0]+$[1]+$[1]+$[2]+$[2];if($.length===8){let X=parseInt($.slice(6,8),16)/255;if($=$.slice(0,6),!/^[0-9a-fA-F]{6}$/.test($))return null;return{...this.#jj(`#${$}`),a:X}}if($.length!==6||!/^[0-9a-fA-F]{6}$/.test($))return null;return Q(this.#jj(`#${$}`))}}}#t(){if(!this.#j)return;let j=this.#h(this.#Q),J=this.#Mj(this.#Q),Q=($)=>this.#j.querySelector(`.${$}`),Z=($,X)=>{let Y=Q($);if(Y)Y.setAttribute("value",X)};switch(this.#f){case"rgb":Z("fig-fill-picker-ci-r",J.r),Z("fig-fill-picker-ci-g",J.g),Z("fig-fill-picker-ci-b",J.b);break;case"hsl":{let $=this.#aj(J);Z("fig-fill-picker-ci-h",Math.round($.h)),Z("fig-fill-picker-ci-s",Math.round($.s)),Z("fig-fill-picker-ci-l",Math.round($.l));break}case"hsb":Z("fig-fill-picker-ci-h",Math.round(this.#Q.h)),Z("fig-fill-picker-ci-s",Math.round(this.#Q.s)),Z("fig-fill-picker-ci-v",Math.round(this.#Q.v));break;case"lab":{let $=this.#Ej(J);Z("fig-fill-picker-ci-okl",Math.round($.l*100)),Z("fig-fill-picker-ci-oka",+$.a.toFixed(3)),Z("fig-fill-picker-ci-okb",+$.b.toFixed(3));break}case"lch":{let $=this.#ej(J);Z("fig-fill-picker-ci-okl",Math.round($.l*100)),Z("fig-fill-picker-ci-okc",+$.c.toFixed(3)),Z("fig-fill-picker-ci-okh",Math.round($.h));break}case"css":Z("fig-fill-picker-ci-css",this.#lj(this.#Q));break;default:Z("fig-fill-picker-ci-hex",j.replace(/^#/,"").toUpperCase());break}if(this.#f!=="css"){let $=Math.round(this.#Q.a*1000)/10;Z("fig-fill-picker-ci-a",Number.isInteger($)?$:+$.toFixed(1))}if(this.#H)this.#H.setAttribute("color",j);this.#U()}#Pj(){let j=this.#j.querySelector('[data-tab="gradient"]'),J=I(this.#J),Q=q("fig-select",{className:"fig-fill-picker-gradient-type",label:"Gradient type",value:this.#J.type},q("fig-select-options",{},[["linear","Linear"],["radial","Radial"],["angular","Angular"]].map(([k,H])=>q("fig-select-option",{value:k},H)))),Z=(k,H,_)=>q("fig-tooltip",{text:k},q("fig-button",{icon:!0,variant:"ghost",className:H,"aria-label":k},F(_))),$=q("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=q("fig-field",{className:"fig-fill-picker-gradient-header"},[Q,$]),Y=q("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.#J)})}),W=q("fig-preview",{className:"fig-fill-picker-gradient-preview"},Y),U=q("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-gradient-add","aria-label":"Add gradient stop",title:"Add stop"},F("add")),K=q("div",{className:"fig-fill-picker-gradient-stops"},[q("fig-header",{className:"fig-fill-picker-gradient-stops-header",borderless:!0},[q("span",{},"Stops"),U]),q("div",{className:"fig-fill-picker-gradient-stops-list"},document.createElement("fig-reorder"))]),O=q("fig-segmented-control",{className:"fig-fill-picker-gradient-interpolation-modes","aria-label":"Color interpolation",value:J},N.#Z.filter((k)=>!k.advanced).map(({value:k,space:H,title:_,subtitle:y})=>q("fig-tooltip",{text:`${_} — ${y}`},q("fig-segment",{value:k,"data-space":H,"aria-label":`${_} — ${y}`},q("fig-interpolation-swatch",{"aria-hidden":"true"}))))),z=q("fig-select",{className:"fig-fill-picker-gradient-space",label:"Color interpolation",value:J},q("fig-select-options",{},this.#Sj())),f=q("div",{className:"fig-fill-picker-gradient-interpolation-more"},[q("fig-button",{icon:!0,variant:"ghost","aria-hidden":"true",tabindex:"-1"},F("more")),z]),L=q("fig-field",{className:"fig-fill-picker-gradient-interpolation-field"},[O,f]);j.replaceChildren(X,W,L,K),this.#P(),this.#Ij(j)}#Sj(){let j=({value:Z,title:$,subtitle:X,advanced:Y=!1})=>q("fig-select-option",{value:Z,label:`${$} — ${X}`,className:Y?"fig-fill-picker-gradient-interpolation-advanced":null},[q("fig-interpolation-swatch",{slot:"prepend",size:"large","aria-hidden":"true"}),q("span",{className:"fig-fill-picker-gradient-interpolation-label"},[q("span",{className:"fig-fill-picker-gradient-interpolation-title"},$),q("span",{className:"fig-fill-picker-gradient-interpolation-subtitle"},X)])]),J=q("fig-separator",{className:"fig-fill-picker-gradient-interpolation-advanced"}),Q=N.#Z;return[...Q.filter((Z)=>!Z.advanced).map(j),J,...Q.filter((Z)=>Z.advanced).map(j)]}#Ij(j){let J=(G)=>typeof G.detail==="string"?G.detail:G.target?.value,Q=j.querySelector(".fig-fill-picker-gradient-bar-input"),Z=(G)=>{if(!Q)return;this.#B=!0;try{Q.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(G)}))}finally{this.#B=!1}},$=()=>{Z(this.#J)};j.querySelector(".fig-fill-picker-gradient-type")?.addEventListener("change",(G)=>{let V=J(G);if(!V)return;this.#J.type=V,this.#P(),this.#z()});let Y=j.querySelector(".fig-fill-picker-gradient-space"),W=Y?.querySelector("fig-select-options"),U="fig-fill-picker-gradient-interpolation-collapsed",K=W?.querySelector(".fig-fill-picker-gradient-interpolation-advanced"),O=()=>Boolean(W?.classList.contains(U)),z=(G)=>{W?.querySelector(".fig-overflow-end")?.setAttribute("aria-label",G?"Show all color interpolation options":"Scroll down")},f=()=>{if(!W)return;W.classList.remove(U),W.style.removeProperty("max-height"),z(!1),W.syncOverflow?.()},L=()=>{if(!W||!K)return;W.style.removeProperty("max-height"),W.classList.add(U),W.scrollTop=0;let G=W.getBoundingClientRect().top,V=K.getBoundingClientRect().top,T=W.querySelector(".fig-overflow-end")?.offsetHeight||0,D=V-G;if(D>0)W.style.maxHeight=`${Math.round(D+T)}px`;z(!0),W.syncOverflow?.()},k=(G)=>Boolean(W?.querySelector(`fig-select-option.fig-fill-picker-gradient-interpolation-advanced[value="${G}"]`)),H=()=>{if(k(I(this.#J)))f();else L()};if(W?.addEventListener("click",(G)=>{if(!O())return;if(!G.target?.closest?.(".fig-overflow-end"))return;G.preventDefault(),G.stopPropagation(),f()},!0),W?.addEventListener("focusin",(G)=>{if(!O())return;if(G.target?.closest?.(".fig-fill-picker-gradient-interpolation-advanced"))f()}),W?.addEventListener("scroll",()=>{if(O()&&W.scrollTop!==0)W.scrollTop=0}),Y?.querySelectorAll("fig-select-option").forEach((G)=>{let V=()=>{let T=C(G.getAttribute("value")||"srgb");Z(M({...this.#J,...T}))};G.addEventListener("pointerenter",V),G.addEventListener("pointerleave",()=>{if(document.activeElement!==G)$()}),G.addEventListener("focus",V),G.addEventListener("blur",()=>{if(!G.matches(":hover"))$()})}),this.#x?.disconnect(),Y)this.#x=new MutationObserver(()=>{if(!Y.hasAttribute("open"))$();else this.#y(H)}),this.#x.observe(Y,{attributes:!0,attributeFilter:["open"]});let _=j.querySelector(".fig-fill-picker-gradient-interpolation-modes");if(_?.addEventListener("change",(G)=>{let V=typeof G.detail==="string"?G.detail:G.target?.value;if(!V)return;let T=C(V);this.#J=M({...this.#J,...T}),this.#P(),this.#z()}),_?.querySelectorAll("fig-segment").forEach((G)=>{let V=()=>{Z(M({...this.#J,...C(G.getAttribute("value")||"srgb")}))};G.addEventListener("pointerenter",V),G.addEventListener("pointerleave",$)}),Y?.addEventListener("change",(G)=>{let V=J(G);if(!V)return;let T=C(V);this.#J=M({...this.#J,...T}),this.#P(),this.#z()}),j.querySelector(".fig-fill-picker-gradient-rotate")?.addEventListener("click",()=>{this.#J.angle=(Number(this.#J.angle)+90)%360,this.#P(),this.#z()}),j.querySelector(".fig-fill-picker-gradient-flip").addEventListener("click",()=>{this.#J.stops.forEach((G)=>{G.position=100-G.position}),this.#J.stops.sort((G,V)=>G.position-V.position),this.#P(),this.#z()}),j.querySelector(".fig-fill-picker-gradient-add").addEventListener("click",()=>{this.#J.stops.push({position:50,color:"#888888",opacity:100}),this.#J.stops.sort((V,T)=>V.position-T.position),this.#P(),this.#z()}),Q){let G=(V)=>{if(V.stopPropagation(),this.#B)return;let T=V.detail;if(!T?.gradient)return;this.#J=M({...this.#J,...T.gradient}),this.#U(),this.#Zj(),this.#yj()};Q.addEventListener("input",(V)=>{G(V),this.#z()}),Q.addEventListener("change",(V)=>{G(V),this.#S()})}j.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(G)=>{this.#vj(G)})}#Bj(j){let J=String(j.color||"#888888").replace(/^#/,"").slice(0,6),Q=j.opacity??100;if(Q>=100)return`#${J}`;let Z=Math.round(Q/100*255).toString(16).padStart(2,"0");return`#${J}${Z}`}#xj(j){if(!(j instanceof HTMLElement))return"#888888";if(j.hexOpaque)return this.#Rj(j.hexOpaque);let J=j.value;if(typeof J==="string"&&J.startsWith("#"))return this.#Rj(J.length>7?J.slice(0,7):J);let Q=j.querySelector('fig-input-text:not([type="number"])'),Z=String(Q?.value??Q?.getAttribute("value")??"").replace(/#/g,"").slice(0,6);if(/^[0-9A-Fa-f]{6}$/.test(Z))return`#${Z.toUpperCase()}`;let $=j.getAttribute("value");if(typeof $==="string"&&$.startsWith("#"))return this.#Rj($.length>7?$.slice(0,7):$);return"#888888"}#Rj(j){let J=String(j||"#888888").replace(/^#/,"").slice(0,6);if(!/^[0-9A-Fa-f]{6}$/.test(J))return"#888888";return`#${J.toUpperCase()}`}#uj(j){let J=j.querySelector(".fig-fill-picker-stop-position"),Q=j.querySelector(".fig-fill-picker-stop-color"),Z=parseFloat(J?.value??J?.getAttribute("value")??"0")||0,$=this.#xj(Q),X=100;if(Q instanceof HTMLElement&&Q.rgba?.a!==void 0)X=Math.round(Q.rgba.a*100);else{let Y=parseInt(j.dataset.index,10);if(!isNaN(Y)&&this.#J.stops[Y])X=this.#J.stops[Y].opacity??100}return{position:Z,color:$,opacity:X}}#_j(j){let J=parseInt(j.dataset.index,10);if(isNaN(J)||J<0||J>=this.#J.stops.length)return;let Q={...this.#J.stops[J],...this.#uj(j)};this.#J.stops[J]=Q,this.#wj(j,Q)}#wj(j,J){let Q=j.querySelector(".fig-fill-picker-stop-position");if(Q)Q.setAttribute("value",String(J.position));let Z=j.querySelector(".fig-fill-picker-stop-color");if(Z)Z.setAttribute("value",this.#Bj(J))}#vj(j){let{oldIndex:J,newIndex:Q}=j.detail??{};if(J==null||Q==null||J===Q||J<0||Q<0||J>=this.#J.stops.length||Q>=this.#J.stops.length)return;let $=j.currentTarget.querySelectorAll(".fig-fill-picker-gradient-stop-row");$.forEach((Y)=>this.#_j(Y));let[X]=this.#J.stops.splice(J,1);this.#J.stops.splice(Q,0,X),$.forEach((Y,W)=>{Y.dataset.index=String(W)}),this.#B=!0;try{this.#Zj(),this.#$j(),this.#z()}finally{this.#B=!1}}#P(){if(!this.#j)return;let j=this.#j.querySelector('[data-tab="gradient"]');if(!j)return;this.#J=M(this.#J);let J=I(this.#J),Q=j.querySelector(".fig-fill-picker-gradient-space");if(Q)Q.value=J;let Z=j.querySelector(".fig-fill-picker-gradient-interpolation-modes");if(Z){let $=N.#$(J),X=Z.querySelector(`fig-segment[value="${J}"]`)||Z.querySelector(`fig-segment[data-space="${$.space}"]`);if(X){let Y=`${$.title} — ${$.subtitle}`;X.setAttribute("value",J),X.setAttribute("aria-label",Y);let W=X.closest("fig-tooltip");if(W)W.setAttribute("text",Y);Z.value=J}}this.#Zj(),this.#$j(),this.#yj()}#bj(){let j=Array.isArray(this.#J.stops)?[...this.#J.stops].sort((J,Q)=>(J.position??0)-(Q.position??0)):[];if(j.length<2)return[{color:"#FF0000",position:0},{color:"#4F9EFF",position:100}];return j.map((J)=>({color:String(J.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:J.position??0}))}#Zj(){if(!this.#j)return;let j=this.#bj();this.#j.querySelectorAll("fig-interpolation-swatch").forEach((J)=>{let Q=J.closest("fig-select-option, fig-segment")?.getAttribute("value")||"srgb",Z=C(Q),$={type:"linear",stops:j,interpolationSpace:Z.interpolationSpace};if(E.has(Z.interpolationSpace))$.hueInterpolation=Z.hueInterpolation;J.value={type:"gradient",gradient:$}})}#$j(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-bar-input");if(j)this.#B=!0,j.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(this.#J)})),this.#B=!1;this.#U()}#yj(){if(!this.#j)return;let j=this.#j.querySelector(".fig-fill-picker-gradient-stops-list"),J=j?.querySelector("fig-reorder");if(!j||!J)return;let Q=J.querySelectorAll(".fig-fill-picker-gradient-stop-row");if(Q.length===this.#J.stops.length){this.#J.stops.forEach((Z,$)=>{let X=Q[$];X.dataset.index=$;let Y=X.querySelector(".fig-fill-picker-stop-position");if(Y)Y.setAttribute("value",Z.position);let W=X.querySelector(".fig-fill-picker-stop-color");if(W)W.setAttribute("value",this.#Bj(Z));let U=X.querySelector(".fig-fill-picker-stop-remove");if(U)if(this.#J.stops.length<=2)U.setAttribute("disabled","");else U.removeAttribute("disabled")});return}this.#gj(j)}#gj(j){let J=j.querySelector("fig-reorder");if(!J)return;let Q=this.#J.stops.map((Z,$)=>q("fig-field",{className:"fig-fill-picker-gradient-stop-row","data-index":$},[q("fig-input-number",{className:"fig-fill-picker-stop-position","aria-label":"Gradient stop position",min:"0",max:"100",value:Z.position,units:"%"}),q("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.#Bj(Z)}),q("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-stop-remove",disabled:this.#J.stops.length<=2,"aria-label":"Remove gradient stop"},F("minus"))]));J.replaceChildren(...Q),J.querySelectorAll(".fig-fill-picker-gradient-stop-row").forEach((Z)=>{Z.querySelector(".fig-fill-picker-stop-position").addEventListener("input",()=>{this.#_j(Z),this.#Zj(),this.#$j(),this.#z()});let $=Z.querySelector(".fig-fill-picker-stop-color"),X=$.querySelector("fig-fill-picker");if(X)X.anchorElement=this.#j;else this.#y(()=>{let W=$.querySelector("fig-fill-picker");if(W)W.anchorElement=this.#j});let Y=()=>{this.#_j(Z),this.#B=!0;try{this.#Zj(),this.#$j(),this.#z()}finally{this.#B=!1}};$.addEventListener("input",Y),$.addEventListener("change",Y),Z.querySelector(".fig-fill-picker-stop-remove").addEventListener("click",()=>{let W=parseInt(Z.dataset.index,10);if(this.#J.stops.length>2)this.#J.stops.splice(W,1),this.#P(),this.#z()})})}#Tj(j,J=!0){let Q=M({...this.#J,interpolationSpace:j??this.#J.interpolationSpace}),Z=this.#T==="display-p3",$=Q.stops.map((W)=>{let U=(W.opacity??100)/100;return`${Z?this.#nj(W.color,U):this.#ij(W.color,U)} ${W.position}%`}).join(", "),X=Jj(Q),Y=J&&X?` ${X}`:"";switch(Q.type){case"linear":return`linear-gradient(${Q.angle}deg${Y}, ${$})`;case"radial":return`radial-gradient(circle at ${Q.centerX}% ${Q.centerY}%${Y}, ${$})`;case"angular":return`conic-gradient(from ${Q.angle}deg${Y}, ${$})`;default:return`linear-gradient(${Q.angle}deg${Y}, ${$})`}}static#Fj=new Map;#Dj(j){let J=N.#Fj.get(j);if(J!==void 0)return J;let Q=document.createElement("div");Q.style.background=j;let Z=!!Q.style.background;return N.#Fj.set(j,Z),Z}#Cj(){let j=this.#Tj(void 0,!0);if(this.#Dj(j))return j;let J=this.#Tj("oklab",!0);if(this.#Dj(J))return J;return this.#Tj("oklab",!1)}#hj(){let j=this.#j.querySelector('[data-tab="image"]'),J=q("fig-select",{className:"fig-fill-picker-scale-mode",label:"Image scale mode",value:this.#W.scaleMode},q("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"],["tile","Tile"]].map(([X,Y])=>q("fig-select-option",{value:X},Y)))),Q=q("fig-input-number",{className:"fig-fill-picker-scale","aria-label":"Image tile scale",min:"1",max:"200",value:this.#W.scale,units:"%"});if(this.#W.scaleMode!=="tile")Q.style.display="none";let Z=q("fig-field",{className:"fig-fill-picker-media-header"},[J,Q]),$=q("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(Z,$),this.#mj(j)}#mj(j){let J=j.querySelector(".fig-fill-picker-scale-mode"),Q=j.querySelector(".fig-fill-picker-scale"),Z=j.querySelector(".fig-fill-picker-image-preview");J.addEventListener("change",($)=>{let X=typeof $.detail==="string"?$.detail:$.target?.value;if(!X)return;this.#W.scaleMode=X,Q.style.display=X==="tile"?"block":"none",this.#s(Z),this.#U(),this.#z()}),Q.addEventListener("input",($)=>{this.#W.scale=parseFloat($.target.value)||100,this.#s(Z),this.#U(),this.#z()}),Z.addEventListener("loaded",($)=>{let X=$.detail?.src||Z.src;if(!X)return;this.#W.url=X,this.#s(Z),this.#U(),this.#z()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#W.url=null,this.#s(Z),this.#U(),this.#z()}),this.#s(Z)}#s(j){if(!this.#W.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.#W.url),j.classList.add("has-media"),j.style.backgroundImage="",j.style.backgroundPosition="",j.style.backgroundRepeat="",j.style.backgroundSize="",j.mediaEl?.style.removeProperty("opacity");let J=j.querySelector("fig-input-file[data-generated]");if(J)J.setAttribute("label","Replace"),J.removeAttribute("url");switch(this.#W.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.#W.url})`,j.style.backgroundPosition="top left",j.style.backgroundSize=`${this.#W.scale}%`,j.style.backgroundRepeat="repeat",j.mediaEl)j.mediaEl.style.opacity="0";break}}#Xj(j){if(j.tagName==="FIG-MEDIA"){if(!this.#O.url){j.removeAttribute("src"),j.classList.remove("has-media");return}j.setAttribute("src",this.#O.url),j.classList.add("has-media");let J=j.querySelector("fig-input-file[data-generated]");if(J)J.setAttribute("label","Replace"),J.removeAttribute("url");switch(this.#O.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.#O.scaleMode){case"fill":case"crop":j.style.objectFit="cover";break;case"fit":j.style.objectFit="contain";break}}#dj(){let j=this.#j.querySelector('[data-tab="video"]'),J=q("fig-select",{className:"fig-fill-picker-scale-mode",label:"Video scale mode",value:this.#O.scaleMode},q("fig-select-options",{},[["fill","Fill"],["fit","Fit"],["crop","Crop"]].map(([$,X])=>q("fig-select-option",{value:$},X)))),Q=q("fig-field",{className:"fig-fill-picker-media-header"},J),Z=q("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(Q,Z),this.#cj(j)}#cj(j){let J=j.querySelector(".fig-fill-picker-scale-mode"),Q=j.querySelector(".fig-fill-picker-video-preview");J.addEventListener("change",(Z)=>{let $=typeof Z.detail==="string"?Z.detail:Z.target?.value;if(!$)return;this.#O.scaleMode=$,this.#Xj(Q),this.#U(),this.#z()}),Q.addEventListener("loaded",(Z)=>{let $=Z.detail?.src||Q.src;if(!$)return;this.#O.url=$,this.#Xj(Q),Q.play?.(),this.#U(),this.#z()}),Q.addEventListener("change",()=>{if(Q.src)return;this.#O.url=null,this.#Xj(Q),this.#U(),this.#z()}),this.#Xj(Q)}#pj(){let j=this.#j.querySelector('[data-tab="webcam"]'),J=q("fig-field",{className:"fig-fill-picker-webcam-camera"},q("fig-select",{className:"fig-fill-picker-camera-select",label:"Camera",full:!0},document.createElement("fig-select-options")));J.style.display="none";let Q=q("video",{className:"fig-fill-picker-webcam-video",autoplay:!0,muted:!0,playsinline:!0});Q.muted=!0;let Z=q("div",{className:"fig-fill-picker-webcam-status",role:"status","aria-live":"polite"},q("span",{},"Camera access required")),$=q("fig-video",{className:"fig-fill-picker-webcam-preview","aria-label":"Webcam preview","aspect-ratio":"1/1",fit:"cover",checkerboard:"true",autoplay:"true",muted:"true"},[Q,Z]),X=q("div",{className:"fig-fill-picker-webcam-controls"},q("fig-button",{className:"fig-fill-picker-webcam-capture",variant:"secondary",full:!0,disabled:!0},"Capture"));j.replaceChildren(J,$,X),this.#sj(j)}#sj(j){let J=j.querySelector(".fig-fill-picker-webcam-video"),Q=j.querySelector(".fig-fill-picker-webcam-status"),Z=j.querySelector(".fig-fill-picker-webcam-capture"),$=j.querySelector(".fig-fill-picker-webcam-camera"),X=j.querySelector(".fig-fill-picker-camera-select"),Y=(K)=>{if(K)Z.removeAttribute("disabled");else Z.setAttribute("disabled","")},W=()=>{let K=!!this.#q.stream&&J.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&J.videoWidth>0&&J.videoHeight>0;if(Y(K),K)Q.querySelector("span").textContent="Camera ready",Q.style.display="none"};J.addEventListener("loadedmetadata",W),J.addEventListener("canplay",W);let U=async(K=null)=>{this.#o();let O=this.#g;Y(!1),Q.querySelector("span").textContent="Starting camera",Q.style.display="flex";try{let z={video:K?{deviceId:{exact:K}}:!0},f=await navigator.mediaDevices.getUserMedia(z);if(O!==this.#g||!this.isConnected||this.#k!=="webcam"){f.getTracks().forEach((H)=>H.stop());return}this.#q.stream=f,J.srcObject=f,J.style.display="block",W();let L=await navigator.mediaDevices.enumerateDevices();if(O!==this.#g)return;let k=L.filter((H)=>H.kind==="videoinput");if(k.length>1){$.style.display="";let H=X.querySelector(":scope > fig-select-options");if(!H)H=document.createElement("fig-select-options"),X.append(H);if(H.replaceChildren(),k.forEach((_,y)=>{let G=document.createElement("fig-select-option");G.value=_.deviceId;let V=_.label||(k.length>1?`Camera ${y+1}`:"Camera");G.textContent=V.replace(/\s*\((?:[0-9a-f]{4}:)*([0-9a-f]{4})\)$/i,(T,D)=>{return` ${/^\d+$/.test(D)?Number.parseInt(D,10).toString():D.replace(/^0+/,"")||"0"}`}),H.append(G)}),K)X.value=K}else $.style.display="none",X.querySelector(":scope > fig-select-options")?.replaceChildren()}catch(z){if(O!==this.#g)return;console.error("Webcam error:",z.name,z.message);let f="Camera access denied";if(z.name==="NotAllowedError")f="Camera permission denied";else if(z.name==="NotFoundError")f="No camera found";else if(z.name==="NotReadableError")f="Camera in use by another app";else if(z.name==="OverconstrainedError")f="Camera constraints not supported";else if(!window.isSecureContext)f="Camera requires secure context";Q.replaceChildren();let L=document.createElement("span");L.textContent=f,Q.appendChild(L),Q.style.display="flex",J.style.display="none",Y(!1)}};this.#Jj=U,X.addEventListener("change",(K)=>{let O=typeof K.detail==="string"?K.detail:K.target?.value;if(O)U(O)}),Z.addEventListener("click",async()=>{if(!this.#q.stream)return;if(!J.videoWidth||!J.videoHeight)return;let K=document.createElement("canvas");K.width=J.videoWidth,K.height=J.videoHeight,K.getContext("2d").drawImage(J,0,0,K.width,K.height);let O=await new Promise((L)=>K.toBlob(L,"image/png"));if(!O)return;if(this.#q.snapshot?.startsWith("blob:"))URL.revokeObjectURL(this.#q.snapshot),this.#c.delete(this.#q.snapshot);this.#q.snapshot=URL.createObjectURL(O),this.#c.add(this.#q.snapshot),this.#W.url=this.#q.snapshot;let z=this.#j.querySelector(".fig-fill-picker-image-preview");if(z)this.#s(z);if(Array.from(this.#j.querySelectorAll(".fig-fill-picker-tab")).some((L)=>L.dataset.tab==="image"))this.#F("image");else this.#U(),this.#z();this.#S()})}#Mj(j){let J=j.h/360,Q=j.s/100,Z=j.v/100,$,X,Y,W=Math.floor(J*6),U=J*6-W,K=Z*(1-Q),O=Z*(1-U*Q),z=Z*(1-(1-U)*Q);switch(W%6){case 0:$=Z,X=z,Y=K;break;case 1:$=O,X=Z,Y=K;break;case 2:$=K,X=Z,Y=z;break;case 3:$=K,X=O,Y=Z;break;case 4:$=z,X=K,Y=Z;break;case 5:$=Z,X=K,Y=O;break}return{r:Math.round($*255),g:Math.round(X*255),b:Math.round(Y*255)}}#e(j){let J=j.r/255,Q=j.g/255,Z=j.b/255,$=Math.max(J,Q,Z),X=Math.min(J,Q,Z),Y=$-X,W=0,U=$===0?0:Y/$,K=$;if($!==X){switch($){case J:W=(Q-Z)/Y+(Q<Z?6:0);break;case Q:W=(Z-J)/Y+2;break;case Z:W=(J-Q)/Y+4;break}W/=6}return{h:W*360,s:U*100,v:K*100,a:1}}#h(j){if(!j||typeof j.h!=="number"||typeof j.s!=="number"||typeof j.v!=="number")return"#D9D9D9";let J=this.#Mj(j),Q=(Z)=>{return(isNaN(Z)?217:Math.max(0,Math.min(255,Math.round(Z)))).toString(16).padStart(2,"0")};return`#${Q(J.r)}${Q(J.g)}${Q(J.b)}`}#jj(j){let J=parseInt(j.slice(1,3),16),Q=parseInt(j.slice(3,5),16),Z=parseInt(j.slice(5,7),16);return this.#e({r:J,g:Q,b:Z})}#ij(j,J=1){let Q=parseInt(j.slice(1,3),16),Z=parseInt(j.slice(3,5),16),$=parseInt(j.slice(5,7),16);return`rgba(${Q}, ${Z}, ${$}, ${J})`}#rj(j){let J=Math.max(0,Math.min(1,Number(j)||0)),Q=Math.round(J*1000)/1000;return String(Q)}#lj(j=this.#Q){let J=this.#Mj(j);return`rgba(${J.r}, ${J.g}, ${J.b}, ${this.#rj(j.a)})`}#oj(j){let J=String(j??"").trim();if(!J)return null;let Q=J.match(/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(Q){let $=Q[1];if($.length===3)$=$[0]+$[0]+$[1]+$[1]+$[2]+$[2];let X=1;if($.length===8)X=parseInt($.slice(6,8),16)/255,$=$.slice(0,6);return{...this.#jj(`#${$}`),a:X}}let Z=J.match(/^rgba?\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))(?:\s*,\s*([+-]?(?:\d+\.?\d*|\.\d+))\s*)?\)$/i);if(Z){let $=Math.max(0,Math.min(255,Math.round(parseFloat(Z[1])))),X=Math.max(0,Math.min(255,Math.round(parseFloat(Z[2])))),Y=Math.max(0,Math.min(255,Math.round(parseFloat(Z[3])))),W=Z[4]!==void 0?Math.max(0,Math.min(1,parseFloat(Z[4]))):1;if(![$,X,Y,W].every(Number.isFinite))return null;return{...this.#e({r:$,g:X,b:Y}),a:W}}return null}#nj(j,J=1){let Q=+(parseInt(j.slice(1,3),16)/255).toFixed(4),Z=+(parseInt(j.slice(3,5),16)/255).toFixed(4),$=+(parseInt(j.slice(5,7),16)/255).toFixed(4);return`color(display-p3 ${Q} ${Z} ${$} / ${J})`}#aj(j){let J=j.r/255,Q=j.g/255,Z=j.b/255,$=Math.max(J,Q,Z),X=Math.min(J,Q,Z),Y,W,U=($+X)/2;if($===X)Y=W=0;else{let K=$-X;switch(W=U>0.5?K/(2-$-X):K/($+X),$){case J:Y=((Q-Z)/K+(Q<Z?6:0))/6;break;case Q:Y=((Z-J)/K+2)/6;break;case Z:Y=((J-Q)/K+4)/6;break}}return{h:Y*360,s:W*100,l:U*100}}#tj(j){let J=j.h/360,Q=j.s/100,Z=j.l/100,$,X,Y;if(Q===0)$=X=Y=Z;else{let W=(O,z,f)=>{if(f<0)f+=1;if(f>1)f-=1;if(f<0.16666666666666666)return O+(z-O)*6*f;if(f<0.5)return z;if(f<0.6666666666666666)return O+(z-O)*(0.6666666666666666-f)*6;return O},U=Z<0.5?Z*(1+Q):Z+Q-Z*Q,K=2*Z-U;$=W(K,U,J+0.3333333333333333),X=W(K,U,J),Y=W(K,U,J-0.3333333333333333)}return{r:Math.round($*255),g:Math.round(X*255),b:Math.round(Y*255)}}#Ej(j){let J=(z)=>{return z=z/255,z<=0.04045?z/12.92:Math.pow((z+0.055)/1.055,2.4)},Q=J(j.r),Z=J(j.g),$=J(j.b),X=0.4122214708*Q+0.5363325363*Z+0.0514459929*$,Y=0.2119034982*Q+0.6806995451*Z+0.1073969566*$,W=0.0883024619*Q+0.2817188376*Z+0.6299787005*$,U=Math.cbrt(X),K=Math.cbrt(Y),O=Math.cbrt(W);return{l:0.2104542553*U+0.793617785*K-0.0040720468*O,a:1.9779984951*U-2.428592205*K+0.4505937099*O,b:0.0259040371*U+0.7827717662*K-0.808675766*O}}#ej(j){let J=this.#Ej(j);return{l:J.l,c:Math.sqrt(J.a*J.a+J.b*J.b),h:(Math.atan2(J.b,J.a)*180/Math.PI+360)%360}}#Aj(j){let J=j.l+0.3963377774*j.a+0.2158037573*j.b,Q=j.l-0.1055613458*j.a-0.0638541728*j.b,Z=j.l-0.0894841775*j.a-1.291485548*j.b,$=J*J*J,X=Q*Q*Q,Y=Z*Z*Z,W=(U)=>{let K=U<=0.0031308?12.92*U:1.055*Math.pow(U,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,K))*255)};return{r:W(4.0767416621*$-3.3077115913*X+0.2309699292*Y),g:W(-1.2684380046*$+2.6097574011*X-0.3413193965*Y),b:W(-0.0041960863*$-0.7034186147*X+1.707614701*Y)}}#jJ(j){let J=j.h*Math.PI/180;return this.#Aj({l:j.l,a:j.c*Math.cos(J),b:j.c*Math.sin(J)})}#z(){if(this.#w())return;this.#U(),this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:this.value}))}#S(){if(this.#w())return;this.#C=JSON.stringify(this.value),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:this.value}))}get value(){let j={type:this.#K,colorSpace:this.#T};switch(this.#K){case"solid":return{...j,color:this.#h(this.#Q),alpha:this.#Q.a,hsv:{...this.#Q}};case"gradient":return{...j,gradient:P(this.#J),css:this.#Cj()};case"image":return{...j,image:{...this.#W}};case"video":return{...j,video:{...this.#O}};case"webcam":return{...j,image:{url:this.#q.snapshot,scaleMode:"fill",scale:50}};default:return{...j,...this.#I[this.#K]}}}set value(j){if(typeof j==="string")this.setAttribute("value",j);else this.setAttribute("value",JSON.stringify(j))}attributeChangedCallback(j,J,Q){if(J===Q)return;switch(j){case"value":if(this.#v(),this.#U(),this.#j?.open&&!this.#N)this.#kj(),this.#C=JSON.stringify(this.value);break;case"disabled":if(this.#E(),this.#w()&&this.#j?.open)this.close();break;case"alpha":case"mode":{if(!this.#j)break;let Z=this.#j.open;if(this.#Qj(),Z&&this.isConnected)this.#l();break}case"aria-label":if(this.#j)this.#j.setAttribute("aria-label",this.#r());case"aria-labelledby":case"aria-describedby":this.#E();break}}}A("fig-fill-picker",N);class B extends HTMLElement{static#Z=new Set(["oklch","hsl"]);static#$=10;static#X=10;static#Y=8;static#j=3;static#_=210;static#k={type:"linear",angle:135,interpolationSpace:"srgb",hueInterpolation:"shorter",stops:[{color:"#FF0000",position:0,opacity:100},{color:"#4F9EFF",position:100,opacity:100}]};#K=!1;#T=null;#Q=null;#f={...B.#k};static get observedAttributes(){return["value"]}get value(){return{type:"gradient",gradient:{...this.#f}}}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.#J(),this.#W(),this.#x(),this.#u()}attributeChangedCallback(j,J,Q){if(J===Q)return;if(j!=="value")return;if(this.#W(),this.#K)this.#u()}#J(){if(!(this.hasAttribute("aria-label")||this.hasAttribute("aria-labelledby"))&&!this.hasAttribute("aria-hidden"))this.setAttribute("aria-hidden","true")}#W(){let j=this.getAttribute("value");if(!j){this.#f={...B.#k,stops:B.#k.stops.map((J)=>({...J}))};return}try{let J=JSON.parse(j),Q=J?.type==="gradient"&&J.gradient?J.gradient:J?.gradient?J.gradient:J;if(!Q||typeof Q!=="object")return;this.#f=this.#O({...B.#k,...Q})}catch{}}#O(j){let J={...j??{}},Q=String(J.interpolationSpace??"srgb").toLowerCase(),Z=String(J.hueInterpolation??"shorter").toLowerCase(),$=Array.isArray(J.stops)?J.stops.map((X)=>({color:String(X?.color||"#D9D9D9").replace(/^(#(?:[0-9a-f]{6})).*/i,"$1"),position:X?.position??0,opacity:X?.opacity??100})):B.#k.stops.map((X)=>({...X}));if($.length<2)return{...B.#k,stops:B.#k.stops.map((X)=>({...X}))};return{type:["linear","radial","angular"].includes(J.type)?J.type:"linear",angle:Number.isFinite(Number(J.angle))?Number(J.angle):135,interpolationSpace:Q,hueInterpolation:Z,stops:$}}#q(){return B.#Z.has(this.#f.interpolationSpace||"srgb")}#V(j){let{r:J,g:Q,b:Z}=p(j);if(this.#f.interpolationSpace==="hsl")return s(J,Q,Z).h;let $=i(J,Q,Z);return(r($.l,$.a,$.b).h%360+360)%360}#I(){let j=this.#N(),J=this.#V(j[0]?.color||"#FF0000"),Q=this.#V(j[j.length-1]?.color||"#4F9EFF"),Z=B.#_-J,X=((B.#_-Q-Z)%360+360)%360,Y=X===0?0:X-360,W=this.#f.hueInterpolation||"shorter",U;if(W==="increasing")U=Y;else if(W==="decreasing")U=X;else if(W==="longer")U=X<180?Y:X;else U=X<=180?X:Y;let K=Math.sign(U),O=Math.asin(B.#j/2/B.#Y)*180/Math.PI,z=Math.min(O,Math.max(0,(Math.abs(U)-0.01)/2));return{startDeg:Z+K*z,sweepDeg:U-K*z*2}}#L(j){let J=j*Math.PI/180;return{x:B.#$+B.#Y*Math.cos(J),y:B.#X+B.#Y*Math.sin(J)}}#G(j,J){let Q=j+J,Z=this.#L(j),$=this.#L(Q),X=Math.abs(J)>180?1:0,Y=J>=0?1:0;return`M ${Z.x} ${Z.y} A ${B.#Y} ${B.#Y} 0 ${X} ${Y} ${$.x} ${$.y}`}#M(){let j=this.#L(180),J=this.#L(0);return`M ${j.x} ${j.y} L ${J.x} ${J.y}`}#H(j){let J=B.#j,Q=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none"><path d="${j}" fill="none" stroke="white" stroke-width="${J}" stroke-linecap="round" stroke-linejoin="round"/></svg>`;return`url("data:image/svg+xml,${encodeURIComponent(Q)}")`}#N(){return[...this.#f.stops].sort((j,J)=>(j.position??0)-(J.position??0))}#B(){let j=this.#f.interpolationSpace||"srgb";if(j==="srgb")return"";if(B.#Z.has(j))return` in ${j} ${this.#f.hueInterpolation||"shorter"} hue`;return` in ${j}`}#R(){let j=this.#N(),J=this.#B();if(this.#q()){let Z=(B.#_+90)%360,$=this.#f.interpolationSpace,X=(W)=>$==="oklch"?`oklch(65% 0.25 ${W})`:`hsl(${W} 100% 50%)`,Y=[0,300,240,180,120,60,0].map(X).join(", ");return`conic-gradient(from ${Z}deg in ${$} decreasing hue, ${Y})`}let Q=j.map((Z)=>`${Z.color} ${Z.position??0}%`).join(", ");return`linear-gradient(90deg${J}, ${Q})`}#x(){if(this.#K)return;let j=B.#j,J=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})),Q=q("div",{className:"fig-interpolation-swatch-fill","aria-hidden":"true"});this.replaceChildren(J,Q),this.#T=J,this.#Q=Q,this.#K=!0}#u(){if(!this.#Q)return;let j=this.#q();if(this.#T)this.#T.style.display=j?"":"none";let J=j?(()=>{let{startDeg:Z,sweepDeg:$}=this.#I();return this.#G(Z,$)})():this.#M(),Q=this.#H(J);this.#Q.style.setProperty("-webkit-mask-image",Q),this.#Q.style.maskImage=Q,this.#Q.style.background=this.#R()}}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=c(),Z.setAttribute("aria-controls",Y.id);let j=document.createElement("slot");if(j.setAttribute("name","panel"),Y.appendChild(j),J.append(Z,Y),this.#X=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)=>T(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.#j,this.#p());return!J&&!Q}#YJ(){this.#z=this.#d(),this.#j=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((B)=>this.#D(B)===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,L=T(this,"full")?this.getBoundingClientRect().left:Y.left-K,W=Y.top-U,z=this.#o();if(typeof J.clampToViewport==="function")({left:L,top:W}=J.clampToViewport({left:L,top:W},X,z));else{let{left:B,top:R}=z,k=window.innerWidth-X.width-z.right,G=window.innerHeight-X.height-z.bottom;L=Math.min(Math.max(L,B),Math.max(B,k)),W=Math.min(Math.max(W,R),Math.max(R,G))}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 V=this.#V(),q=this.#w($);if(q&&V&&V.scrollHeight>V.clientHeight+1){let B=q.top-Y.top;if(Math.abs(B)>0.5)V.scrollTop+=B;V.syncOverflow?.()}if(this.#Q||this.open)this.#YJ()}#HJ(){this.#X?.addEventListener("click",this.#I),this.#X?.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.#X?.removeEventListener("click",this.#I),this.#X?.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(T(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(($)=>!T($,"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=T(this,"disabled");if(this.#X)if(J)this.#X.setAttribute("disabled","");else this.#X.removeAttribute("disabled");if(J&&this.open)this.open=!1}#a(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}#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)=>T(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.#X?.setAttribute("aria-label",j),this.#V()?.syncOverflow?.(),X)this.#E(this.getAttribute("value")??"")}finally{this.#k=!1}}#kJ(J){if(T(this,"disabled"))return;J.preventDefault(),J.stopPropagation();let Q=!this.open;if(Q&&this.#Y&&this.#X)this.#Y.anchor=this.#X;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(T(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(T(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.#X?.contains(J.target)&&(J.key==="ArrowDown"||J.key==="Enter"||J.key===" ")){if(J.preventDefault(),this.#Y&&this.#X)this.#Y.anchor=this.#X;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.#X?.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.#X?.setAttribute("aria-expanded","false"),this.#X?.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.#X)return;let J=Math.ceil(this.getBoundingClientRect().width),Q=Math.ceil(this.#X.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.#X)this.#Y.anchor=this.#X;this.#l(),this.#Q=!1,this.#z=null,this.#j=null,this.#h(),this.#VJ(),this.#Y.open=!0,document.addEventListener("keydown",this.#f,!0),this.#X?.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.#X?.hasAttribute("data-focus-visible")||this.#X?.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.#j=null,document.removeEventListener("keydown",this.#f,!0),this.#Y.open=!1,this.#X?.setAttribute("aria-expanded","false")}}A("fig-select",m);var JJ=["srgb","srgb-linear","display-p3","oklab","oklch","hsl"],QJ=["shorter","longer","increasing","decreasing"],E=new Set(["oklch","hsl"]);function y(J){let Q={...J??{}},Z=String(Q.interpolationSpace??"srgb").toLowerCase();if(!JJ.includes(Z))Z="srgb";Q.interpolationSpace=Z;let $=String(Q.hueInterpolation??"shorter").toLowerCase();return Q.hueInterpolation=QJ.includes($)?$:"shorter",Q}function P(J){let Q=y(J),Z={...Q,interpolationSpace:Q.interpolationSpace};if(E.has(Q.interpolationSpace))Z.hueInterpolation=Q.hueInterpolation;else delete Z.hueInterpolation;return Z}function ZJ(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 x(J){let Q=y(J);if(E.has(Q.interpolationSpace))return`${Q.interpolationSpace}-${Q.hueInterpolation||"shorter"}`;return Q.interpolationSpace}function C(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 $J=0;class N extends HTMLElement{static#X=[{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.#X,Z=Q.find((K)=>K.value===J);if(Z)return Z;let $=C(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-${++$J}`;#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};#j={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.#j.url??null;return{url:J,poster:this.#j.poster??null,scaleMode:this.#j.scaleMode||"fill",scale:this.#j.scale??50,opacity:this.#j.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.#j.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=y({...this.#Q,...Z.gradient});if(Z.image)this.#z={...this.#z,...Z.image};if(Z.video)this.#j={...this.#j,...Z.video},this.#j.missing=!this.#j.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=S(this.#z.url);let X=this.#KJ(this.#z.scaleMode,this.#z.scale);Q=X.size,Z=X.position}else J="";break;case"video":if(this.#j.poster){J=S(this.#j.poster);let X=this.#KJ(this.#j.scaleMode,this.#j.scale);Q=X.size,Z=X.position}else J="";break;case"webcam":if(this.#$.snapshot){J=S(this.#$.snapshot);let X=this.#KJ(this.#$.scaleMode,this.#$.scale);Q=X.size,Z=X.position}else J="";break;default:J=this.#_[this.#U]?.element?.getAttribute("swatch-background")||"#D9D9D9"}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((z)=>{let V=z.getAttribute("slot").slice(5);this.#_[V]={element:z,label:z.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[z,{label:V}]of Object.entries(this.#_))Y[z]=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 z=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",value:this.#U},z)}let K=X.map((z)=>f("div",{className:"fig-fill-picker-tab","data-tab":z})),U=f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-close","aria-label":"Close fill picker"},F("close"));this.#J.replaceChildren(f("fig-header",{},[j,U]),f("fig-content",{},K)),document.body.appendChild(this.#J);for(let[z,{element:V}]of Object.entries(this.#_)){let q=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((B)=>B.dataset.tab===z);if(!q)continue;while(V.firstChild)q.appendChild(V.firstChild);this.dispatchEvent(new CustomEvent("modeready",{bubbles:!0,detail:{mode:z,container:q}}))}let O=this.#J.querySelector(".fig-fill-picker-type");if(O)O.addEventListener("change",(z)=>{let V=typeof z.detail==="string"?z.detail:z.target?.value;if(V)this.#s(V)});this.#J.querySelector(".fig-fill-picker-close").addEventListener("click",()=>{this.#J.open=!1});let L=()=>{if(this.#W)this.#W.removeAttribute("selected");if(this.#YJ())this.#JJ();else this.#N();let z=JSON.stringify(this.value);if(this.#x!==null&&this.#x!==z)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",L);let W={solid:()=>this.#gJ(),gradient:()=>this.#pJ(),image:()=>this.#eJ(),video:()=>this.#QQ(),webcam:()=>this.#$Q()};for(let[z,V]of Object.entries(W))if(!this.#_[z]&&X.includes(z))V();for(let z of Object.keys(this.#_)){if(Q.includes(z))continue;let V=Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).find((q)=>q.dataset.tab===z);if(!V)continue;V.addEventListener("input",(q)=>{if(q.target===this)return;if(q.stopPropagation(),q.detail)this.#F[z]=q.detail;this.#O()}),V.addEventListener("change",(q)=>{if(q.target===this)return;if(q.stopPropagation(),q.detail)this.#F[z]=q.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.#j.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"},F("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,z])=>f("fig-select-option",{value:W},z))),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 z=typeof W.detail==="string"?W.detail:W.target?.value;if(!z)return;this.#G=z,this.#SJ()}),this.#SJ();let L=J.querySelector(".fig-fill-picker-eyedropper");if("EyeDropper"in window)L.addEventListener("click",async()=>{try{let z=await new EyeDropper().open();this.#Z={...this.#XJ(z.sRGBHex),a:this.#Z.a},this.#i(),this.#g(),this.#QJ(),this.#O()}catch(W){}});else L.setAttribute("disabled",""),L.title="EyeDropper not supported in this browser"}#LQ(){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,O,L]=hslToP3(X,100,50);j.addColorStop(1,`color(display-p3 ${U} ${O} ${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,$)}#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,$=(O,L={})=>{let W=J.getBoundingClientRect();if(W.width===0||W.height===0)return;let z=Math.max(0,Math.min(O.clientX-W.left,W.width)),V=Math.max(0,Math.min(O.clientY-W.top,W.height));this.#yJ(z/W.width,V/W.height,L)},X=(O)=>{if(O.button!==0)return;if(O.target===Q||Q.contains(O.target))return;Z=!0,this.#M=!0,J.setPointerCapture(O.pointerId),$(O,{updateHandle:!0,emitInput:!0})},Y=(O)=>{if(!Z)return;if(O.buttons===0){j();return}$(O,{updateHandle:!0,emitInput:!0})},j=()=>{if(!Z)return;Z=!1,this.#M=!1,this.#S()},K=(O)=>{this.#M=!0;let L=O.detail?.px,W=O.detail?.py;if(!Number.isFinite(L)||!Number.isFinite(W))return;Q.setAttribute("value",`${L*100}% ${W*100}%`),this.#yJ(L,W,{updateHandle:!1,emitInput:!0})},U=(O)=>{let L=O.detail?.px,W=O.detail?.py;if(Number.isFinite(L)&&Number.isFinite(W))Q.setAttribute("value",`${L*100}% ${W*100}%`),this.#yJ(L,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,O,L,W,z)=>f("fig-input-number",{className:K,"aria-label":U,min:O,max:L,step:W,units:z}),$=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.#OQ({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.#GQ({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.#WQ($.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.#zQ(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.#fQ(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.#KQ(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=x(this.#Q),Z=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(([q,B])=>f("fig-select-option",{value:q},B)))),$=(q,B,R)=>f("fig-tooltip",{text:q},f("fig-button",{icon:!0,variant:"ghost",className:B,"aria-label":q},F(R))),X=f("div",{className:"fig-fill-picker-gradient-actions"},[$("Flip gradient","fig-fill-picker-gradient-flip","swap"),$("Rotate gradient","fig-fill-picker-gradient-rotate","rotate")]),Y=f("fig-field",{className:"fig-fill-picker-gradient-header"},[Z,X]),j=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)})}),K=f("fig-preview",{className:"fig-fill-picker-gradient-preview"},j),U=f("fig-button",{icon:!0,variant:"ghost",className:"fig-fill-picker-gradient-add","aria-label":"Add gradient stop",title:"Add stop"},F("add")),O=f("div",{className:"fig-fill-picker-gradient-stops"},[f("fig-header",{className:"fig-fill-picker-gradient-stops-header",borderless:!0},[f("span",{},"Stops"),U]),f("div",{className:"fig-fill-picker-gradient-stops-list"},document.createElement("fig-reorder"))]),L=f("fig-segmented-control",{className:"fig-fill-picker-gradient-interpolation-modes","aria-label":"Color interpolation",value:Q},N.#X.filter((q)=>!q.advanced).map(({value:q,space:B,title:R,subtitle:k})=>f("fig-tooltip",{text:`${R} — ${k}`},f("fig-segment",{value:q,"data-space":B,"aria-label":`${R} — ${k}`},f("fig-interpolation-swatch",{"aria-hidden":"true"}))))),W=f("fig-select",{className:"fig-fill-picker-gradient-space",label:"Color interpolation",value:Q},f("fig-select-options",{},this.#sJ())),z=f("div",{className:"fig-fill-picker-gradient-interpolation-more"},[f("fig-button",{icon:!0,variant:"ghost","aria-hidden":"true",tabindex:"-1"},F("more")),W]),V=f("fig-field",{className:"fig-fill-picker-gradient-interpolation-field"},[L,z]);J.replaceChildren(Y,K,V,O),this.#P(),this.#iJ(J)}#sJ(){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.#X;return[...Z.filter(($)=>!$.advanced).map(J),Q,...Z.filter(($)=>$.advanced).map(J)]}#iJ(J){let Q=(G)=>typeof G.detail==="string"?G.detail:G.target?.value,Z=J.querySelector(".fig-fill-picker-gradient-bar-input"),$=(G)=>{if(!Z)return;this.#V=!0;try{Z.setAttribute("value",JSON.stringify({type:"gradient",gradient:P(G)}))}finally{this.#V=!1}},X=()=>{$(this.#Q)};J.querySelector(".fig-fill-picker-gradient-type")?.addEventListener("change",(G)=>{let H=Q(G);if(!H)return;this.#Q.type=H,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",O=K?.querySelector(".fig-fill-picker-gradient-interpolation-advanced"),L=()=>Boolean(K?.classList.contains(U)),W=(G)=>{K?.querySelector(".fig-overflow-end")?.setAttribute("aria-label",G?"Show all color interpolation options":"Scroll down")},z=()=>{if(!K)return;K.classList.remove(U),K.style.removeProperty("max-height"),W(!1),K.syncOverflow?.()},V=()=>{if(!K||!O)return;K.style.removeProperty("max-height"),K.classList.add(U),K.scrollTop=0;let G=K.getBoundingClientRect().top,H=O.getBoundingClientRect().top,M=K.querySelector(".fig-overflow-end")?.offsetHeight||0,D=H-G;if(D>0)K.style.maxHeight=`${Math.round(D+M)}px`;W(!0),K.syncOverflow?.()},q=(G)=>Boolean(K?.querySelector(`fig-select-option.fig-fill-picker-gradient-interpolation-advanced[value="${G}"]`)),B=()=>{if(q(x(this.#Q)))z();else V()};if(K?.addEventListener("click",(G)=>{if(!L())return;if(!G.target?.closest?.(".fig-overflow-end"))return;G.preventDefault(),G.stopPropagation(),z()},!0),K?.addEventListener("focusin",(G)=>{if(!L())return;if(G.target?.closest?.(".fig-fill-picker-gradient-interpolation-advanced"))z()}),K?.addEventListener("scroll",()=>{if(L()&&K.scrollTop!==0)K.scrollTop=0}),j?.querySelectorAll("fig-select-option").forEach((G)=>{let H=()=>{let M=C(G.getAttribute("value")||"srgb");$(y({...this.#Q,...M}))};G.addEventListener("pointerenter",H),G.addEventListener("pointerleave",()=>{if(document.activeElement!==G)X()}),G.addEventListener("focus",H),G.addEventListener("blur",()=>{if(!G.matches(":hover"))X()})}),this.#A?.disconnect(),j)this.#A=new MutationObserver(()=>{if(!j.hasAttribute("open"))X();else this.#y(B)}),this.#A.observe(j,{attributes:!0,attributeFilter:["open"]});let R=J.querySelector(".fig-fill-picker-gradient-interpolation-modes");if(R?.addEventListener("change",(G)=>{let H=typeof G.detail==="string"?G.detail:G.target?.value;if(!H)return;let M=C(H);this.#Q=y({...this.#Q,...M}),this.#P(),this.#O()}),R?.querySelectorAll("fig-segment").forEach((G)=>{let H=()=>{$(y({...this.#Q,...C(G.getAttribute("value")||"srgb")}))};G.addEventListener("pointerenter",H),G.addEventListener("pointerleave",X)}),j?.addEventListener("change",(G)=>{let H=Q(G);if(!H)return;let M=C(H);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((G)=>{G.position=100-G.position}),this.#Q.stops.sort((G,H)=>G.position-H.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((H,M)=>H.position-M.position),this.#P(),this.#O()}),Z){let G=(H)=>{if(H.stopPropagation(),this.#V)return;let M=H.detail;if(!M?.gradient)return;this.#Q=y({...this.#Q,...M.gradient}),this.#L(),this.#WJ(),this.#IJ()};Z.addEventListener("input",(H)=>{G(H),this.#O()}),Z.addEventListener("change",(H)=>{G(H),this.#S()})}J.querySelector(".fig-fill-picker-gradient-stops-list > fig-reorder")?.addEventListener("reorder",(G)=>{this.#nJ(G)})}#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}${$}`}#rJ(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()}`}#lJ(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.#rJ(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.#lJ(J)};this.#Q.stops[Q]=Z,this.#oJ(J,Z)}#oJ(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))}#nJ(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=y(this.#Q);let Q=x(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()}#aJ(){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.#aJ();this.#J.querySelectorAll("fig-interpolation-swatch").forEach((Q)=>{let Z=Q.closest("fig-select-option, fig-segment")?.getAttribute("value")||"srgb",$=C(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.#tJ(J)}#tJ(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"},F("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.#UQ(K.color,U):this.#YQ(K.color,U)} ${K.position}%`}).join(", "),Y=ZJ(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)}#eJ(){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.#JQ(J)}#JQ(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.#j.url){J.removeAttribute("src"),J.classList.remove("has-media");return}J.setAttribute("src",this.#j.url),J.classList.add("has-media");let Q=J.querySelector("fig-input-file[data-generated]");if(Q)Q.setAttribute("label","Replace"),Q.removeAttribute("url");switch(this.#j.scaleMode){case"fill":case"crop":J.setAttribute("fit","cover");break;case"fit":J.setAttribute("fit","contain");break}return}switch(J.style.objectPosition="center",J.style.width="100%",J.style.height="100%",this.#j.scaleMode){case"fill":case"crop":J.style.objectFit="cover";break;case"fit":J.style.objectFit="contain";break}}#QQ(){let J=this.#J.querySelector('[data-tab="video"]'),Q=f("fig-select",{className:"fig-fill-picker-scale-mode",label:"Video scale mode",value:this.#j.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.#ZQ(J),this.#qJ()}#bJ(){if(this.#j.poster?.startsWith("blob:"))URL.revokeObjectURL(this.#j.poster),this.#u.delete(this.#j.poster);this.#j.poster=null}#qJ({emit:J=!0}={}){if(this.#j.url){if(this.#j.missing=!1,!this.#j.poster)this.#EJ(this.#j.url,{emit:J});return}let Q=this.getAttribute("default-video");if(!Q){this.#j.missing=!0;return}this.#j.url=Q,this.#j.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.#j.poster=URL.createObjectURL(X),this.#u.add(this.#j.poster),this.#L(),Q)this.#O()}catch{}}#ZQ(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.#j.scaleMode=X,this.#ZJ(Z),this.#L(),this.#O()}),Z.addEventListener("loaded",($)=>{let X=$.detail?.src||Z.src;if(!X)return;this.#j.url=X,this.#j.missing=!1,this.#ZJ(Z),Z.play?.(),this.#EJ(X),this.#L(),this.#O()}),Z.addEventListener("change",()=>{if(Z.src)return;this.#j.url=null,this.#bJ(),this.#qJ(),this.#ZJ(Z),this.#L(),this.#O()}),this.#ZJ(Z)}#$Q(){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.#XQ(J)}#XQ(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()},O=async(W,z)=>{let V=await navigator.mediaDevices.enumerateDevices();if(W!=null&&W!==this.#w)return;let q=V.filter((B)=>B.kind==="videoinput");if(q.length>1){X.style.display="";let B=Y.querySelector(":scope > fig-select-options");if(!B)B=document.createElement("fig-select-options"),Y.append(B);if(B.replaceChildren(),q.forEach((R,k)=>{let G=document.createElement("fig-select-option");G.value=R.deviceId;let H=R.label||(q.length>1?`Camera ${k+1}`:"Camera");G.textContent=H.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"}`}),B.append(G)}),z)Y.value=z}else X.style.display="none",Y.querySelector(":scope > fig-select-options")?.replaceChildren()},L=async(W=null)=>{let z=W||this.#$.deviceId||null,V=this.#$.stream,q=V?.getTracks?.().filter((R)=>R.readyState!=="ended")??[];if(V&&q.length){let R=this.#$.deviceId;if(!z||!R||z===R){U(V),this.#jJ(),O(null,z||R);return}}this.#N({emit:Boolean(V)});let B=this.#w;j(!1),Z.querySelector("span").textContent="Starting camera",Z.style.display="flex";try{let R={video:z?{deviceId:{exact:z}}:!0},k=await navigator.mediaDevices.getUserMedia(R);if(B!==this.#w||!this.isConnected||this.#q!=="webcam"){k.getTracks().forEach((H)=>H.stop());return}let G=k.getVideoTracks?.()?.[0];this.#$.deviceId=z||G?.getSettings?.()?.deviceId||null,this.#$.live=this.#n()==="live",U(k),this.#jJ(),await O(B,z)}catch(R){if(B!==this.#w)return;console.error("Webcam error:",R.name,R.message);let k="Camera access denied";if(R.name==="NotAllowedError")k="Camera permission denied";else if(R.name==="NotFoundError")k="No camera found";else if(R.name==="NotReadableError")k="Camera in use by another app";else if(R.name==="OverconstrainedError")k="Camera constraints not supported";else if(!window.isSecureContext)k="Camera requires secure context";Z.replaceChildren();let G=document.createElement("span");G.textContent=k,Z.appendChild(G),Z.style.display="flex",Q.style.display="none",j(!1)}};this.#l=L,Y.addEventListener("change",(W)=>{let z=typeof W.detail==="string"?W.detail:W.target?.value;if(!z)return;this.#$.deviceId=z,L(z)}),$.addEventListener("click",async()=>{if(!this.#$.stream)return;let W=await this.#v(Q);if(!W)return;this.#z.url=W,this.#$.live=!1;let z=this.#J.querySelector(".fig-fill-picker-image-preview");if(z)this.#r(z);if(Array.from(this.#J.querySelectorAll(".fig-fill-picker-tab")).some((q)=>q.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,O=$*(1-Z),L=$*(1-U*Z),W=$*(1-(1-U)*Z);switch(K%6){case 0:X=$,Y=W,j=O;break;case 1:X=L,Y=$,j=O;break;case 2:X=O,Y=$,j=W;break;case 3:X=O,Y=L,j=$;break;case 4:X=W,Y=O,j=$;break;case 5:X=$,Y=O,j=L;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,O=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:O*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:$})}#YQ(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})`}#jQ(J){let Q=Math.max(0,Math.min(1,Number(J)||0)),Z=Math.round(Q*1000)/1000;return String(Z)}#KQ(J=this.#Z){let Q=this.#AJ(J);return`rgba(${Q.r}, ${Q.g}, ${Q.b}, ${this.#jQ(J.a)})`}#WQ(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}#UQ(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})`}#zQ(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 O=X-Y;switch(K=U>0.5?O/(2-X-Y):O/(X+Y),X){case Q:j=((Z-$)/O+(Z<$?6:0))/6;break;case Z:j=(($-Q)/O+2)/6;break;case $:j=((Q-Z)/O+4)/6;break}}return{h:j*360,s:K*100,l:U*100}}#OQ(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,z)=>{if(z<0)z+=1;if(z>1)z-=1;if(z<0.16666666666666666)return L+(W-L)*6*z;if(z<0.5)return W;if(z<0.6666666666666666)return L+(W-L)*(0.6666666666666666-z)*6;return L},U=$<0.5?$*(1+Z):$+Z-$*Z,O=2*$-U;X=K(O,U,Q+0.3333333333333333),Y=K(O,U,Q),j=K(O,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),O=Math.cbrt(j),L=Math.cbrt(K);return{l:0.2104542553*U+0.793617785*O-0.0040720468*L,a:1.9779984951*U-2.428592205*O+0.4505937099*L,b:0.0259040371*U+0.7827717662*O-0.808675766*L}}#fQ(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 O=U<=0.0031308?12.92*U:1.055*Math.pow(U,0.4166666666666667)-0.055;return Math.round(Math.max(0,Math.min(1,O))*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)}}#GQ(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 _ extends HTMLElement{static#X=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={..._.#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={..._.#q,stops:_.#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.#j({..._.#q,...Z})}catch{}}#j(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})):_.#q.stops.map((Y)=>({...Y}));if(X.length<2)return{..._.#q,stops:_.#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 _.#X.has(this.#G.interpolationSpace||"srgb")}#I(J){let{r:Q,g:Z,b:$}=s(J);if(this.#G.interpolationSpace==="hsl")return i(Q,Z,$).h;let X=r(Q,Z,$);return(l(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"),$=_.#R-Q,Y=((_.#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 O=Math.sign(U),L=Math.asin(_.#J/2/_.#W)*180/Math.PI,W=Math.min(L,Math.max(0,(Math.abs(U)-0.01)/2));return{startDeg:$+O*W,sweepDeg:U-O*W*2}}#F(J){let Q=J*Math.PI/180;return{x:_.#Y+_.#W*Math.cos(Q),y:_.#K+_.#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 ${_.#W} ${_.#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=_.#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(_.#X.has(J))return` in ${J} ${this.#G.hueInterpolation||"shorter"} hue`;return` in ${J}`}#V(){let J=this.#B(),Q=this.#M();if(this.#$()){let $=(_.#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=_.#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",_);
|