@rogieking/figui3 5.1.0 → 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/fig-editor.js CHANGED
@@ -1,6 +1,62 @@
1
- import { gradientToValueShape, gradientInterpolationClause, normalizeGradientConfig } from "./fig.js";
2
-
3
1
  // FigFillPicker
2
+ const GRADIENT_INTERPOLATION_SPACES = [
3
+ "srgb",
4
+ "srgb-linear",
5
+ "display-p3",
6
+ "oklab",
7
+ "oklch",
8
+ ];
9
+ const GRADIENT_HUE_INTERPOLATIONS = [
10
+ "shorter",
11
+ "longer",
12
+ "increasing",
13
+ "decreasing",
14
+ ];
15
+
16
+ function normalizeGradientConfig(gradient) {
17
+ const next = { ...(gradient ?? {}) };
18
+ let interpolationSpace = String(
19
+ next.interpolationSpace ?? "oklab",
20
+ ).toLowerCase();
21
+ if (!GRADIENT_INTERPOLATION_SPACES.includes(interpolationSpace)) {
22
+ interpolationSpace = "oklab";
23
+ }
24
+ if (interpolationSpace === "srgb" || interpolationSpace === "display-p3") {
25
+ interpolationSpace = "oklab";
26
+ }
27
+ next.interpolationSpace = interpolationSpace;
28
+
29
+ const hueInterpolation = String(
30
+ next.hueInterpolation ?? "shorter",
31
+ ).toLowerCase();
32
+ next.hueInterpolation = GRADIENT_HUE_INTERPOLATIONS.includes(hueInterpolation)
33
+ ? hueInterpolation
34
+ : "shorter";
35
+ return next;
36
+ }
37
+
38
+ function gradientToValueShape(gradient) {
39
+ const normalized = normalizeGradientConfig(gradient);
40
+ const output = {
41
+ ...normalized,
42
+ interpolationSpace: normalized.interpolationSpace,
43
+ };
44
+ if (normalized.interpolationSpace === "oklch") {
45
+ output.hueInterpolation = normalized.hueInterpolation;
46
+ } else {
47
+ delete output.hueInterpolation;
48
+ }
49
+ return output;
50
+ }
51
+
52
+ function gradientInterpolationClause(gradient) {
53
+ const normalized = normalizeGradientConfig(gradient);
54
+ if (normalized.interpolationSpace === "oklch") {
55
+ return `in oklch ${normalized.hueInterpolation} hue`;
56
+ }
57
+ return `in ${normalized.interpolationSpace}`;
58
+ }
59
+
4
60
  /**
5
61
  * A comprehensive fill picker component supporting solid colors, gradients, images, video, and webcam.
6
62
  * Uses display: contents and wraps a trigger element that opens a dialog picker.
package/fig.js CHANGED
@@ -3632,6 +3632,7 @@ customElements.define("fig-options", FigOptions);
3632
3632
  class FigSlider extends HTMLElement {
3633
3633
  #isInteracting = false;
3634
3634
  #showEmptyTextValue = false;
3635
+ #value = "";
3635
3636
  // Private fields declarations
3636
3637
  #typeDefaults = {
3637
3638
  range: { min: 0, max: 100, step: 1 },
@@ -3826,6 +3827,29 @@ class FigSlider extends HTMLElement {
3826
3827
  this.#regenerateInnerHTML();
3827
3828
  }
3828
3829
 
3830
+ get value() {
3831
+ if (this.#value !== "") return this.#value;
3832
+ const rawValue = this.getAttribute("value");
3833
+ if (rawValue !== null) return String(this.#normalizeSliderValue(rawValue));
3834
+ return "";
3835
+ }
3836
+
3837
+ set value(value) {
3838
+ const normalized = String(this.#normalizeSliderValue(value));
3839
+ this.#value = normalized;
3840
+ if (this.input && this.input.value !== normalized) {
3841
+ this.input.value = normalized;
3842
+ this.input.setAttribute("aria-valuenow", normalized);
3843
+ }
3844
+ if (this.figInputNumber) {
3845
+ this.figInputNumber.setAttribute(
3846
+ "value",
3847
+ this.#showEmptyTextValue ? "" : normalized,
3848
+ );
3849
+ }
3850
+ if (this.input) this.#syncProperties();
3851
+ }
3852
+
3829
3853
  disconnectedCallback() {
3830
3854
  if (this.input) {
3831
3855
  this.input.removeEventListener("input", this.#boundHandleInput);
@@ -5815,7 +5839,7 @@ const GRADIENT_HUE_INTERPOLATIONS = [
5815
5839
 
5816
5840
  const GRADIENT_PICKER_SPACES = ["srgb-linear", "oklab", "oklch"];
5817
5841
 
5818
- export function normalizeGradientConfig(gradient) {
5842
+ function normalizeGradientConfig(gradient) {
5819
5843
  const next = { ...(gradient ?? {}) };
5820
5844
  let interpolationSpace = String(
5821
5845
  next.interpolationSpace ?? "oklab",
@@ -5837,7 +5861,7 @@ export function normalizeGradientConfig(gradient) {
5837
5861
  return next;
5838
5862
  }
5839
5863
 
5840
- export function gradientToValueShape(gradient) {
5864
+ function gradientToValueShape(gradient) {
5841
5865
  const normalized = normalizeGradientConfig(gradient);
5842
5866
  const output = {
5843
5867
  ...normalized,
@@ -5851,7 +5875,7 @@ export function gradientToValueShape(gradient) {
5851
5875
  return output;
5852
5876
  }
5853
5877
 
5854
- export function gradientInterpolationClause(gradient) {
5878
+ function gradientInterpolationClause(gradient) {
5855
5879
  const normalized = normalizeGradientConfig(gradient);
5856
5880
  if (normalized.interpolationSpace === "oklch") {
5857
5881
  return `in oklch ${normalized.hueInterpolation} hue`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
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",