@rogieking/figui3 3.21.1 → 3.21.2

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/fig.js CHANGED
@@ -6364,6 +6364,8 @@ class FigInputGradient extends HTMLElement {
6364
6364
  ...this.#gradient,
6365
6365
  ...parsed.gradient,
6366
6366
  });
6367
+ this.#gradient.type = "linear";
6368
+ this.#gradient.angle = 90;
6367
6369
  return;
6368
6370
  }
6369
6371
  if (parsed?.gradient) {
@@ -6371,6 +6373,8 @@ class FigInputGradient extends HTMLElement {
6371
6373
  ...this.#gradient,
6372
6374
  ...parsed.gradient,
6373
6375
  });
6376
+ this.#gradient.type = "linear";
6377
+ this.#gradient.angle = 90;
6374
6378
  }
6375
6379
  } catch (e) {
6376
6380
  // Ignore invalid JSON and keep current/default gradient.
@@ -12902,10 +12906,15 @@ class FigColorTip extends HTMLElement {
12902
12906
  }
12903
12907
  this.removeEventListener("click", this.#handleControlClick);
12904
12908
 
12905
- const color = this.#normalizeColor(this.getAttribute("value"));
12909
+ const rawValue = (this.getAttribute("value") || "").trim();
12910
+ const color = this.#normalizeColor(rawValue);
12911
+ const alpha = this.#extractAlpha(rawValue);
12906
12912
  const alphaAttr = this.#alphaEnabled ? "" : 'alpha="false"';
12913
+ const pickerValue = alpha < 1
12914
+ ? JSON.stringify({ type: "solid", color, opacity: Math.round(alpha * 100) })
12915
+ : JSON.stringify({ type: "solid", color });
12907
12916
  this.innerHTML = `
12908
- <fig-fill-picker mode="solid" ${alphaAttr} value='${JSON.stringify({ type: "solid", color })}'>
12917
+ <fig-fill-picker mode="solid" ${alphaAttr} value='${pickerValue}'>
12909
12918
  <fig-chit background="${color}"></fig-chit>
12910
12919
  </fig-fill-picker>`;
12911
12920
 
@@ -12940,6 +12949,17 @@ class FigColorTip extends HTMLElement {
12940
12949
  return "#D9D9D9";
12941
12950
  }
12942
12951
 
12952
+ #extractAlpha(colorValue) {
12953
+ if (!colorValue) return 1;
12954
+ const v = String(colorValue).trim();
12955
+ if (v.startsWith("#") && v.length === 9) {
12956
+ return parseInt(v.slice(7, 9), 16) / 255;
12957
+ }
12958
+ const rgbaMatch = v.match(/rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*([\d.]+)\s*\)/i);
12959
+ if (rgbaMatch) return parseFloat(rgbaMatch[1]);
12960
+ return 1;
12961
+ }
12962
+
12943
12963
  #normalizeColor(colorValue) {
12944
12964
  if (!colorValue) return "#D9D9D9";
12945
12965
  const value = String(colorValue).trim();
@@ -12983,17 +13003,19 @@ class FigColorTip extends HTMLElement {
12983
13003
  }
12984
13004
 
12985
13005
  #syncFromAttributes() {
12986
- const color = this.#normalizeColor(this.getAttribute("value"));
12987
- if (this.getAttribute("value") !== color) {
13006
+ const rawAttr = this.getAttribute("value");
13007
+ const color = this.#normalizeColor(rawAttr);
13008
+ const alpha = this.#extractAlpha(rawAttr);
13009
+ if (rawAttr !== color && alpha >= 1) {
12988
13010
  this.setAttribute("value", color);
12989
13011
  return;
12990
13012
  }
12991
13013
 
12992
13014
  if (this.#fillPicker) {
12993
- this.#fillPicker.setAttribute(
12994
- "value",
12995
- JSON.stringify({ type: "solid", color }),
12996
- );
13015
+ const pickerVal = alpha < 1
13016
+ ? { type: "solid", color, opacity: Math.round(alpha * 100) }
13017
+ : { type: "solid", color };
13018
+ this.#fillPicker.setAttribute("value", JSON.stringify(pickerVal));
12997
13019
  if (this.#alphaEnabled) {
12998
13020
  this.#fillPicker.removeAttribute("alpha");
12999
13021
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "3.21.1",
3
+ "version": "3.21.2",
4
4
  "description": "A lightweight web components library for building Figma plugin and widget UIs with native look and feel",
5
5
  "author": "Rogie King",
6
6
  "license": "MIT",