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