@rogieking/figui3 6.11.0 → 6.13.0

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-lab.css CHANGED
@@ -302,13 +302,15 @@ fig-field-slider {
302
302
  background-color: transparent;
303
303
  box-shadow: none !important;
304
304
  position: absolute;
305
- right: 0;
305
+ right: 2px;
306
+ top:2px;
307
+ bottom:2px;
306
308
  width: fit-content;
307
309
  min-width: fit-content;
308
310
  max-width: max-content;
309
311
  flex: 0 0 auto;
310
312
  border-left: 0;
311
- border-radius: var(--radius-small);
313
+ border-radius: var(--radius-medium);
312
314
 
313
315
  &:hover,
314
316
  &:has(input:focus) {
@@ -321,7 +323,7 @@ fig-field-slider {
321
323
  input {
322
324
  field-sizing: content;
323
325
  font-variant-numeric: tabular-nums;
324
- border-radius: var(--radius-small);
326
+ border-radius: var(--radius-medium);
325
327
  width: auto;
326
328
  flex: 0 0 auto;
327
329
  text-align: right;
@@ -704,18 +706,18 @@ fig-reorder {
704
706
  display: contents;
705
707
  }
706
708
 
707
- fig-reorder:not([handle]):not([disabled]):not([disabled="false"]) > [data-reorder-item] {
709
+ fig-reorder:not([handle]):is(:not([disabled]), [disabled="false"]) > [data-reorder-item] {
708
710
  cursor: grab;
709
711
  }
710
712
 
711
- fig-reorder:not([handle]):not([disabled]):not([disabled="false"]) > [data-reorder-item] > fig-header,
712
- fig-reorder:not([handle]):not([disabled]):not([disabled="false"]) > [data-reorder-item] > fig-header *,
713
- fig-reorder:not([handle]):not([disabled]):not([disabled="false"]) > [data-reorder-item] > label {
713
+ fig-reorder:not([handle]):is(:not([disabled]), [disabled="false"]) > [data-reorder-item] > fig-header,
714
+ fig-reorder:not([handle]):is(:not([disabled]), [disabled="false"]) > [data-reorder-item] > fig-header *,
715
+ fig-reorder:not([handle]):is(:not([disabled]), [disabled="false"]) > [data-reorder-item] > label {
714
716
  cursor: grab;
715
717
  }
716
718
 
717
719
  fig-reorder > .dragging {
718
- opacity: 0.6;
720
+ background-color: var(--figma-color-bg-selected);
719
721
  }
720
722
 
721
723
  [data-reorder-handle] {
@@ -736,7 +738,7 @@ body.fig-reorder-dragging * {
736
738
  .fig-reorder-indicator {
737
739
  position: fixed;
738
740
  pointer-events: none;
739
- z-index: 10000;
741
+ z-index: 1000000;
740
742
  background: var(--figma-color-border-strong);
741
743
  }
742
744
 
@@ -747,4 +749,3 @@ body.fig-reorder-dragging * {
747
749
  .fig-reorder-indicator[data-axis="horizontal"] {
748
750
  width: 2px;
749
751
  }
750
-
package/fig-lab.js CHANGED
@@ -8,6 +8,10 @@
8
8
  * <script src="fig-lab.js"></script>
9
9
  */
10
10
 
11
+ function figLabBooleanAttribute(element, name) {
12
+ return element.hasAttribute(name) && element.getAttribute(name) !== "false";
13
+ }
14
+
11
15
  /* Field + Slider wrapper */
12
16
  class FigFieldSlider extends HTMLElement {
13
17
  #field = null;
@@ -331,7 +335,7 @@ class FigFieldSlider extends HTMLElement {
331
335
  }
332
336
 
333
337
  #handleElasticPointerDown(event) {
334
- if (event.button !== 0 || this.hasAttribute("disabled")) return;
338
+ if (event.button !== 0 || figLabBooleanAttribute(this, "disabled")) return;
335
339
  if (this.getAttribute("elastic") === "false") return;
336
340
  if (event.target?.closest?.("fig-input-number")) return;
337
341
  const rangeInput =
@@ -397,7 +401,7 @@ class FigFieldSlider extends HTMLElement {
397
401
  }
398
402
 
399
403
  #handleContextMenu(event) {
400
- if (this.hasAttribute("disabled")) return;
404
+ if (figLabBooleanAttribute(this, "disabled")) return;
401
405
  event.preventDefault();
402
406
  event.stopPropagation();
403
407
  event.stopImmediatePropagation();
@@ -872,7 +876,7 @@ class FigCanvasControl extends HTMLElement {
872
876
  this.#radiusTooltip = null;
873
877
  this.#angleTooltip = null;
874
878
 
875
- const disabled = this.hasAttribute("disabled");
879
+ const disabled = figLabBooleanAttribute(this, "disabled");
876
880
  const type = this.#type;
877
881
  const tooltips = this.#tooltipsEnabled;
878
882
 
@@ -945,7 +949,7 @@ class FigCanvasControl extends HTMLElement {
945
949
  }
946
950
 
947
951
  #activateMoveCursor(e) {
948
- if (this.hasAttribute("disabled")) return;
952
+ if (figLabBooleanAttribute(this, "disabled")) return;
949
953
  if (e?.button !== undefined && e.button !== 0) return;
950
954
  if (e?.isPrimary === false) return;
951
955
 
@@ -1190,7 +1194,7 @@ class FigCanvasControl extends HTMLElement {
1190
1194
 
1191
1195
  #setupLineDrag(hitLine) {
1192
1196
  hitLine.addEventListener("pointerdown", (e) => {
1193
- if (this.hasAttribute("disabled")) return;
1197
+ if (figLabBooleanAttribute(this, "disabled")) return;
1194
1198
  e.preventDefault();
1195
1199
  e.stopPropagation();
1196
1200
  const container = this.#container;
@@ -1705,7 +1709,7 @@ class FigCanvasControl extends HTMLElement {
1705
1709
  circle.style.cursor = this.#resizeCursorSvg(deg);
1706
1710
  });
1707
1711
  const onDown = (e) => {
1708
- if (this.hasAttribute("disabled")) return;
1712
+ if (figLabBooleanAttribute(this, "disabled")) return;
1709
1713
  e.preventDefault();
1710
1714
  e.stopPropagation();
1711
1715
  this.#isRadiusDragging = true;
@@ -1830,6 +1834,7 @@ class FigInputOscillator extends HTMLElement {
1830
1834
  #precision = 2;
1831
1835
  #drawWidth = 240;
1832
1836
  #drawHeight = 120;
1837
+ #valueRange = { min: -1, max: 1 };
1833
1838
  #isDragging = null;
1834
1839
  #svg = null;
1835
1840
  #path = null;
@@ -1935,7 +1940,9 @@ class FigInputOscillator extends HTMLElement {
1935
1940
 
1936
1941
  #readInteger(name, fallback) {
1937
1942
  const value = Number.parseInt(this.getAttribute(name) || "", 10);
1938
- return Number.isFinite(value) ? value : fallback;
1943
+ return Number.isFinite(value)
1944
+ ? Math.max(0, Math.min(100, value))
1945
+ : fallback;
1939
1946
  }
1940
1947
 
1941
1948
  #readBooleanAttribute(name, defaultValue = false) {
@@ -2231,12 +2238,12 @@ class FigInputOscillator extends HTMLElement {
2231
2238
  }
2232
2239
 
2233
2240
  #toY(value) {
2234
- const { min, max } = this.#getValueRange();
2241
+ const { min, max } = this.#valueRange;
2235
2242
  return this.#drawHeight - ((value - min) / (max - min)) * this.#drawHeight;
2236
2243
  }
2237
2244
 
2238
2245
  #fromY(y) {
2239
- const { min, max } = this.#getValueRange();
2246
+ const { min, max } = this.#valueRange;
2240
2247
  return min + (1 - y / this.#drawHeight) * (max - min);
2241
2248
  }
2242
2249
 
@@ -2251,6 +2258,7 @@ class FigInputOscillator extends HTMLElement {
2251
2258
  #updateWaveform() {
2252
2259
  if (!this.#svg || !this.#path) return;
2253
2260
  this.#syncViewportSize();
2261
+ this.#valueRange = this.#getValueRange();
2254
2262
 
2255
2263
  if (this.#bounds) {
2256
2264
  this.#bounds.setAttribute("width", this.#drawWidth);
@@ -3420,12 +3428,14 @@ class FigReorder extends HTMLElement {
3420
3428
 
3421
3429
  #startPendingDrag(event, item, target) {
3422
3430
  this.#cancelDrag();
3431
+ FigReorder.#setDocumentDragging(true);
3423
3432
 
3424
3433
  const state = {
3425
3434
  item,
3426
3435
  target,
3427
3436
  pointerId: event.pointerId,
3428
3437
  oldIndex: this.#getElementChildren().indexOf(item),
3438
+ targetIndex: this.#getElementChildren().indexOf(item),
3429
3439
  startX: event.clientX,
3430
3440
  startY: event.clientY,
3431
3441
  active: false,
@@ -3448,7 +3458,6 @@ class FigReorder extends HTMLElement {
3448
3458
  event.preventDefault();
3449
3459
  event.stopPropagation();
3450
3460
  item.classList.add("dragging");
3451
- FigReorder.#setDocumentDragging(true);
3452
3461
  try {
3453
3462
  target.setPointerCapture(state.pointerId);
3454
3463
  } catch {}
@@ -3458,7 +3467,7 @@ class FigReorder extends HTMLElement {
3458
3467
  const pointer =
3459
3468
  this.#axis === "horizontal" ? moveEvent.clientX : moveEvent.clientY;
3460
3469
  const index = this.#getInsertIndex(pointer);
3461
- this.#moveItemToIndex(item, index);
3470
+ state.targetIndex = index;
3462
3471
  this.#updateIndicator(index, item);
3463
3472
  };
3464
3473
 
@@ -3470,7 +3479,7 @@ class FigReorder extends HTMLElement {
3470
3479
 
3471
3480
  state.onUp = (upEvent) => {
3472
3481
  if (upEvent.pointerId !== state.pointerId) return;
3473
- this.#finishDrag(state, false);
3482
+ this.#finishDrag(state, upEvent.type === "pointercancel");
3474
3483
  };
3475
3484
 
3476
3485
  this.#drag = state;
@@ -3502,6 +3511,8 @@ class FigReorder extends HTMLElement {
3502
3511
 
3503
3512
  const clamped = Math.max(0, Math.min(index, items.length));
3504
3513
 
3514
+ if (index === currentIndex) return false;
3515
+
3505
3516
  // Hide only the redundant bottom line when the dragged item is already last.
3506
3517
  if (clamped >= items.length && currentIndex === items.length - 1) {
3507
3518
  return false;
@@ -3620,9 +3631,8 @@ class FigReorder extends HTMLElement {
3620
3631
  window.removeEventListener("keydown", onKeyDown);
3621
3632
 
3622
3633
  if (active) {
3623
- if (revert) {
3624
- this.#restoreItemIndex(item, oldIndex);
3625
- } else {
3634
+ if (!revert) {
3635
+ this.#moveItemToIndex(item, state.targetIndex);
3626
3636
  const newIndex = this.#getElementChildren().indexOf(item);
3627
3637
  if (newIndex !== -1 && newIndex !== oldIndex) {
3628
3638
  this.dispatchEvent(
@@ -3641,16 +3651,6 @@ class FigReorder extends HTMLElement {
3641
3651
  if (this.#drag === state) this.#drag = null;
3642
3652
  }
3643
3653
 
3644
- #restoreItemIndex(item, index) {
3645
- const items = this.#getElementChildren().filter((node) => node !== item);
3646
- const ref = items[index] ?? null;
3647
- if (ref) {
3648
- this.insertBefore(item, ref);
3649
- return;
3650
- }
3651
- this.appendChild(item);
3652
- }
3653
-
3654
3654
  #unbindAll() {
3655
3655
  for (const [, binding] of this.#bindings) {
3656
3656
  binding.target.removeEventListener(
@@ -3669,4 +3669,3 @@ class FigReorder extends HTMLElement {
3669
3669
  }
3670
3670
 
3671
3671
  customElements.define("fig-reorder", FigReorder);
3672
-