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