@rogieking/figui3 3.20.2 → 3.20.3

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.
Files changed (2) hide show
  1. package/fig.js +33 -13
  2. package/package.json +1 -1
package/fig.js CHANGED
@@ -6260,12 +6260,13 @@ class FigInputGradient extends HTMLElement {
6260
6260
  return this.#gradient.stops
6261
6261
  .map(
6262
6262
  (stop, i) =>
6263
- `<fig-tooltip action="manual" text="${Math.round(stop.position)}%"><fig-handle drag drag-axes="x" drag-surface=".fig-input-gradient-track" type="color" color="${stop.color}" value="${stop.position}% 50%" data-stop-index="${i}"${disabled ? " disabled" : ""}></fig-handle></fig-tooltip>`,
6263
+ `<fig-tooltip action="manual" text="${Math.round(stop.position)}%"><fig-handle drag drag-axes="x" drag-surface=".fig-input-gradient-track" type="color" color="${stop.color}" value="${stop.position}% 50%" hit-area="4" data-stop-index="${i}"${disabled ? " disabled" : ""}></fig-handle></fig-tooltip>`,
6264
6264
  )
6265
6265
  .join("");
6266
6266
  }
6267
6267
 
6268
6268
  #ghostHandle = null;
6269
+ #addedOnPointerDown = false;
6269
6270
 
6270
6271
  #render() {
6271
6272
  const disabled = this.hasAttribute("disabled");
@@ -6301,22 +6302,14 @@ class FigInputGradient extends HTMLElement {
6301
6302
 
6302
6303
  const ghost = document.createElement("fig-handle");
6303
6304
  ghost.classList.add("fig-input-gradient-ghost");
6305
+ ghost.setAttribute("type", "color");
6306
+ ghost.setAttribute("control", "add");
6304
6307
  ghost.style.position = "absolute";
6305
6308
  ghost.style.top = "50%";
6306
6309
  ghost.style.transform = "translate(-50%, -50%)";
6307
6310
  ghost.style.pointerEvents = "none";
6308
6311
  ghost.style.opacity = "0";
6309
6312
  ghost.style.transition = "opacity 0.15s";
6310
- ghost.style.overflow = "visible";
6311
-
6312
- const tip = document.createElement("fig-color-tip");
6313
- tip.setAttribute("control", "add");
6314
- tip.style.position = "absolute";
6315
- tip.style.bottom = "calc(100% + 6px)";
6316
- tip.style.left = "50%";
6317
- tip.style.transform = "translateX(-50%)";
6318
- tip.style.zIndex = "10";
6319
- ghost.appendChild(tip);
6320
6313
 
6321
6314
  this.#track.appendChild(ghost);
6322
6315
  this.#ghostHandle = ghost;
@@ -6392,6 +6385,10 @@ class FigInputGradient extends HTMLElement {
6392
6385
  #onTrackClick = (e) => {
6393
6386
  if (!this.#track) return;
6394
6387
  if (this.#handleDragging) return;
6388
+ if (this.#addedOnPointerDown) {
6389
+ this.#addedOnPointerDown = false;
6390
+ return;
6391
+ }
6395
6392
  if (e.target.closest("fig-handle:not(.fig-input-gradient-ghost)")) {
6396
6393
  if (e.shiftKey) {
6397
6394
  const clickedHandle = e.target.closest("fig-handle");
@@ -6524,6 +6521,7 @@ class FigInputGradient extends HTMLElement {
6524
6521
  if (e.target.closest("fig-handle:not(.fig-input-gradient-ghost)")) return;
6525
6522
  if (e.button !== 0) return;
6526
6523
  e.preventDefault();
6524
+ e.stopPropagation();
6527
6525
 
6528
6526
  const trackRect = this.#track.getBoundingClientRect();
6529
6527
  const pct = Math.max(0, Math.min(1, (e.clientX - trackRect.left) / trackRect.width));
@@ -6534,6 +6532,7 @@ class FigInputGradient extends HTMLElement {
6534
6532
  const newIndex = this.#gradient.stops.findIndex(
6535
6533
  (s) => s.position === position && s.color === color,
6536
6534
  );
6535
+ this.#addedOnPointerDown = true;
6537
6536
  this.#syncHandles();
6538
6537
  this.#syncChit();
6539
6538
  this.#emitInput();
@@ -6544,6 +6543,9 @@ class FigInputGradient extends HTMLElement {
6544
6543
  );
6545
6544
  const newHandle = handles[newIndex];
6546
6545
  if (newHandle) {
6546
+ this.#track.querySelectorAll("fig-handle:not(.fig-input-gradient-ghost)").forEach((h) => {
6547
+ if (h !== newHandle) h.deselect();
6548
+ });
6547
6549
  newHandle.select();
6548
6550
  newHandle.dispatchEvent(new PointerEvent("pointerdown", {
6549
6551
  bubbles: true,
@@ -6561,6 +6563,15 @@ class FigInputGradient extends HTMLElement {
6561
6563
  const handle = e.target.closest("fig-handle");
6562
6564
  if (!handle) return;
6563
6565
  e.stopPropagation();
6566
+ if (e.detail?.color) {
6567
+ const idx = parseInt(handle.dataset.stopIndex, 10);
6568
+ if (!isNaN(idx) && this.#gradient.stops[idx]) {
6569
+ this.#gradient.stops[idx].color = e.detail.color;
6570
+ this.#syncChit();
6571
+ this.#emitInput();
6572
+ }
6573
+ return;
6574
+ }
6564
6575
  if (!this.#handleDragging) handle.style.zIndex = "5";
6565
6576
  this.#handleDragging = true;
6566
6577
  const idx = parseInt(handle.dataset.stopIndex, 10);
@@ -6603,6 +6614,15 @@ class FigInputGradient extends HTMLElement {
6603
6614
  const handle = e.target.closest("fig-handle");
6604
6615
  if (!handle) return;
6605
6616
  e.stopPropagation();
6617
+ if (e.detail?.color) {
6618
+ const idx = parseInt(handle.dataset.stopIndex, 10);
6619
+ if (!isNaN(idx) && this.#gradient.stops[idx]) {
6620
+ this.#gradient.stops[idx].color = e.detail.color;
6621
+ this.#syncChit();
6622
+ this.#emitChange();
6623
+ }
6624
+ return;
6625
+ }
6606
6626
  handle.style.zIndex = "";
6607
6627
  const tooltip = handle.closest("fig-tooltip");
6608
6628
  if (tooltip) tooltip.removeAttribute("show");
@@ -14480,7 +14500,7 @@ class FigHandle extends HTMLElement {
14480
14500
  document.addEventListener("keydown", this.#handleKeyDown);
14481
14501
  const initial = this.getAttribute("value");
14482
14502
  if (initial) this.#applyValue(initial);
14483
- if (this.#hasControlMode && !this.#isGhost) this.#showColorTip();
14503
+ if (this.#hasControlMode) this.#showColorTip();
14484
14504
  }
14485
14505
 
14486
14506
  disconnectedCallback() {
@@ -14544,7 +14564,7 @@ class FigHandle extends HTMLElement {
14544
14564
  if (name === "value" && !this.#applyingValue && !this.#isDragging) {
14545
14565
  this.#applyValue(value);
14546
14566
  }
14547
- if (name === "control" && !this.#isGhost) {
14567
+ if (name === "control") {
14548
14568
  if (this.#hasControlMode) {
14549
14569
  this.#hideColorTip();
14550
14570
  this.#showColorTip();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "3.20.2",
3
+ "version": "3.20.3",
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",