@rogieking/figui3 6.7.1 → 6.7.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.
package/fig.js CHANGED
@@ -3550,10 +3550,9 @@ class FigTabs extends HTMLElement {
3550
3550
  #boundSyncOverflow = this.#syncOverflow.bind(this);
3551
3551
  #mutationObserver = null;
3552
3552
  #resizeObserver = null;
3553
- #scroller = null;
3554
3553
  #navStart = null;
3555
3554
  #navEnd = null;
3556
- #isStructuring = false;
3555
+ #isUnwrapping = false;
3557
3556
 
3558
3557
  constructor() {
3559
3558
  super();
@@ -3568,10 +3567,11 @@ class FigTabs extends HTMLElement {
3568
3567
  connectedCallback() {
3569
3568
  this.name = this.getAttribute("name") || "tabs";
3570
3569
  this.setAttribute("role", "tablist");
3571
- this.#ensureScroller();
3570
+ if (this.shadowRoot) this.shadowRoot.replaceChildren();
3571
+ this.#removeLegacyScroller();
3572
3572
  this.addEventListener("click", this.#boundHandleClick);
3573
3573
  this.addEventListener("keydown", this.#boundHandleKeyDown);
3574
- this.#scrollElement.addEventListener("scroll", this.#boundSyncOverflow);
3574
+ this.addEventListener("scroll", this.#boundSyncOverflow);
3575
3575
  this.#createNavButtons();
3576
3576
  this.#startObserver();
3577
3577
  this.#startResizeObserver();
@@ -3589,30 +3589,6 @@ class FigTabs extends HTMLElement {
3589
3589
  });
3590
3590
  }
3591
3591
 
3592
- get #scrollElement() {
3593
- return this.#scroller || this;
3594
- }
3595
-
3596
- get scrollLeft() {
3597
- return this.#scrollElement.scrollLeft;
3598
- }
3599
-
3600
- set scrollLeft(value) {
3601
- this.#scrollElement.scrollLeft = value;
3602
- }
3603
-
3604
- get scrollWidth() {
3605
- return this.#scrollElement.scrollWidth;
3606
- }
3607
-
3608
- scrollTo(...args) {
3609
- this.#scrollElement.scrollTo(...args);
3610
- }
3611
-
3612
- scrollBy(...args) {
3613
- this.#scrollElement.scrollBy(...args);
3614
- }
3615
-
3616
3592
  #applyDisabled(disabled) {
3617
3593
  const tabs = this.querySelectorAll("fig-tab");
3618
3594
  tabs.forEach((tab) => {
@@ -3652,17 +3628,16 @@ class FigTabs extends HTMLElement {
3652
3628
 
3653
3629
  requestAnimationFrame(() => {
3654
3630
  if (!this.isConnected || !target.isConnected) return;
3655
- const scrollEl = this.#scrollElement;
3656
- const overflowX = scrollEl.scrollWidth > scrollEl.clientWidth;
3631
+ const overflowX = this.scrollWidth > this.clientWidth;
3657
3632
  if (!overflowX) return;
3658
3633
 
3659
- const containerRect = scrollEl.getBoundingClientRect();
3634
+ const containerRect = this.getBoundingClientRect();
3660
3635
  const tabRect = target.getBoundingClientRect();
3661
3636
  const tabCenter =
3662
- tabRect.left - containerRect.left + scrollEl.scrollLeft + tabRect.width / 2;
3637
+ tabRect.left - containerRect.left + this.scrollLeft + tabRect.width / 2;
3663
3638
 
3664
- scrollEl.scrollTo({
3665
- left: tabCenter - scrollEl.clientWidth / 2,
3639
+ this.scrollTo({
3640
+ left: tabCenter - this.clientWidth / 2,
3666
3641
  behavior,
3667
3642
  });
3668
3643
  this.#syncOverflow();
@@ -3672,7 +3647,7 @@ class FigTabs extends HTMLElement {
3672
3647
  disconnectedCallback() {
3673
3648
  this.removeEventListener("click", this.#boundHandleClick);
3674
3649
  this.removeEventListener("keydown", this.#boundHandleKeyDown);
3675
- this.#scrollElement.removeEventListener("scroll", this.#boundSyncOverflow);
3650
+ this.removeEventListener("scroll", this.#boundSyncOverflow);
3676
3651
  this.#mutationObserver?.disconnect();
3677
3652
  this.#mutationObserver = null;
3678
3653
  this.#resizeObserver?.disconnect();
@@ -3680,68 +3655,35 @@ class FigTabs extends HTMLElement {
3680
3655
  this.#removeNavButtons();
3681
3656
  }
3682
3657
 
3683
- #ensureScroller() {
3684
- if (this.#isStructuring) return;
3685
- const existing = this.querySelector(":scope > [data-fig-tabs-scroll]");
3686
- const directNodes = existing
3687
- ? Array.from(this.childNodes).filter((node) => {
3688
- if (node === existing) return false;
3689
- if (node.nodeType !== Node.ELEMENT_NODE) return true;
3690
- return !node.hasAttribute("data-fig-tabs-nav");
3691
- })
3692
- : null;
3693
- if (existing && existing === this.#scroller && !directNodes?.length) return;
3658
+ #removeLegacyScroller() {
3659
+ if (this.#isUnwrapping) return;
3660
+ const legacy = this.querySelector(":scope > [data-fig-tabs-scroll]");
3661
+ if (!legacy) return;
3694
3662
 
3695
- this.#isStructuring = true;
3663
+ this.#isUnwrapping = true;
3696
3664
  try {
3697
- const previousScroller = this.#scroller;
3698
- if (previousScroller && previousScroller !== existing) {
3699
- previousScroller.removeEventListener("scroll", this.#boundSyncOverflow);
3700
- }
3701
-
3702
- const scroller = existing || document.createElement("div");
3703
- scroller.className = "fig-tabs-scroll";
3704
- scroller.dataset.figTabsScroll = "";
3705
-
3706
- const nodes =
3707
- directNodes ??
3708
- Array.from(this.childNodes).filter((node) => {
3709
- if (node === scroller) return false;
3710
- if (node.nodeType !== Node.ELEMENT_NODE) return true;
3711
- return !node.hasAttribute("data-fig-tabs-nav");
3712
- });
3713
-
3714
- for (const node of nodes) {
3715
- scroller.appendChild(node);
3716
- }
3717
-
3718
- if (!existing) this.prepend(scroller);
3719
-
3720
- this.#scroller = scroller;
3721
- this.#scroller.removeEventListener("scroll", this.#boundSyncOverflow);
3722
- this.#scroller.addEventListener("scroll", this.#boundSyncOverflow);
3723
- if (this.#resizeObserver) this.#resizeObserver.observe(this.#scroller);
3665
+ const nodes = Array.from(legacy.childNodes);
3666
+ legacy.replaceWith(...nodes);
3724
3667
  } finally {
3725
- this.#isStructuring = false;
3668
+ this.#isUnwrapping = false;
3726
3669
  }
3727
3670
  }
3728
3671
 
3729
3672
  #syncOverflow() {
3730
- figSyncOverflowState(this, this.#scrollElement, "x");
3673
+ figSyncOverflowState(this, this, "x");
3731
3674
  }
3732
3675
 
3733
3676
  #startResizeObserver() {
3734
3677
  this.#resizeObserver?.disconnect();
3735
3678
  this.#resizeObserver = new ResizeObserver(() => this.#syncOverflow());
3736
3679
  this.#resizeObserver.observe(this);
3737
- if (this.#scroller) this.#resizeObserver.observe(this.#scroller);
3738
3680
  }
3739
3681
 
3740
3682
  #startObserver() {
3741
3683
  this.#mutationObserver?.disconnect();
3742
3684
  this.#mutationObserver = new MutationObserver(() => {
3743
- if (this.#isStructuring) return;
3744
- this.#ensureScroller();
3685
+ if (this.#isUnwrapping) return;
3686
+ this.#removeLegacyScroller();
3745
3687
  this.#createNavButtons();
3746
3688
  this.#syncTabIndexes();
3747
3689
  requestAnimationFrame(() => {
@@ -3749,7 +3691,7 @@ class FigTabs extends HTMLElement {
3749
3691
  this.#scrollSelectedTabIntoView();
3750
3692
  });
3751
3693
  });
3752
- this.#mutationObserver.observe(this, { childList: true, subtree: true });
3694
+ this.#mutationObserver.observe(this, { childList: true, subtree: false });
3753
3695
  }
3754
3696
 
3755
3697
  #removeNavButtons() {
@@ -3775,8 +3717,8 @@ class FigTabs extends HTMLElement {
3775
3717
 
3776
3718
  const buttons = createFigOverflowButtons({
3777
3719
  owner: "tabs",
3778
- onStart: () => figScrollOverflowPage(this.#scrollElement, "x", -1),
3779
- onEnd: () => figScrollOverflowPage(this.#scrollElement, "x", 1),
3720
+ onStart: () => figScrollOverflowPage(this, "x", -1),
3721
+ onEnd: () => figScrollOverflowPage(this, "x", 1),
3780
3722
  });
3781
3723
  this.#navStart = buttons.start;
3782
3724
  this.#navEnd = buttons.end;
@@ -14967,11 +14909,10 @@ class FigChooser extends HTMLElement {
14967
14909
  #boundSyncOverflow = this.#syncOverflow.bind(this);
14968
14910
  #mutationObserver = null;
14969
14911
  #resizeObserver = null;
14970
- #scroller = null;
14971
14912
  #navStart = null;
14972
14913
  #navEnd = null;
14973
14914
  #dragState = null;
14974
- #isStructuring = false;
14915
+ #isUnwrapping = false;
14975
14916
 
14976
14917
  constructor() {
14977
14918
  super();
@@ -15016,43 +14957,7 @@ class FigChooser extends HTMLElement {
15016
14957
  }
15017
14958
 
15018
14959
  get choices() {
15019
- return Array.from((this.#scroller || this).querySelectorAll(this.#choiceSelector));
15020
- }
15021
-
15022
- get #scrollElement() {
15023
- return this.#scroller || this;
15024
- }
15025
-
15026
- get scrollTop() {
15027
- return this.#scrollElement.scrollTop;
15028
- }
15029
-
15030
- set scrollTop(value) {
15031
- this.#scrollElement.scrollTop = value;
15032
- }
15033
-
15034
- get scrollLeft() {
15035
- return this.#scrollElement.scrollLeft;
15036
- }
15037
-
15038
- set scrollLeft(value) {
15039
- this.#scrollElement.scrollLeft = value;
15040
- }
15041
-
15042
- get scrollWidth() {
15043
- return this.#scrollElement.scrollWidth;
15044
- }
15045
-
15046
- get scrollHeight() {
15047
- return this.#scrollElement.scrollHeight;
15048
- }
15049
-
15050
- scrollTo(...args) {
15051
- this.#scrollElement.scrollTo(...args);
15052
- }
15053
-
15054
- scrollBy(...args) {
15055
- this.#scrollElement.scrollBy(...args);
14960
+ return Array.from(this.querySelectorAll(`:scope > ${this.#choiceSelector}`));
15056
14961
  }
15057
14962
 
15058
14963
  get selectedChoice() {
@@ -15092,11 +14997,12 @@ class FigChooser extends HTMLElement {
15092
14997
 
15093
14998
  connectedCallback() {
15094
14999
  this.setAttribute("role", "listbox");
15000
+ if (this.shadowRoot) this.shadowRoot.replaceChildren();
15095
15001
  this.#syncGridColumns();
15096
- this.#ensureScroller();
15002
+ this.#removeLegacyScroller();
15097
15003
  this.addEventListener("click", this.#boundHandleClick);
15098
15004
  this.addEventListener("keydown", this.#boundHandleKeyDown);
15099
- this.#scrollElement.addEventListener("scroll", this.#boundSyncOverflow);
15005
+ this.addEventListener("scroll", this.#boundSyncOverflow);
15100
15006
  this.#applyOverflowMode();
15101
15007
  this.#setupDrag();
15102
15008
  this.#startObserver();
@@ -15140,7 +15046,7 @@ class FigChooser extends HTMLElement {
15140
15046
  disconnectedCallback() {
15141
15047
  this.removeEventListener("click", this.#boundHandleClick);
15142
15048
  this.removeEventListener("keydown", this.#boundHandleKeyDown);
15143
- this.#scrollElement.removeEventListener("scroll", this.#boundSyncOverflow);
15049
+ this.removeEventListener("scroll", this.#boundSyncOverflow);
15144
15050
  this.#teardownDrag();
15145
15051
  this.#mutationObserver?.disconnect();
15146
15052
  this.#mutationObserver = null;
@@ -15323,7 +15229,7 @@ class FigChooser extends HTMLElement {
15323
15229
  #syncOverflow() {
15324
15230
  if (this.#overflowMode === "scrollbar") return;
15325
15231
  const isHorizontal = this.getAttribute("layout") === "horizontal";
15326
- figSyncOverflowState(this, this.#scrollElement, isHorizontal ? "x" : "y");
15232
+ figSyncOverflowState(this, this, isHorizontal ? "x" : "y");
15327
15233
  }
15328
15234
 
15329
15235
  #startResizeObserver() {
@@ -15332,30 +15238,29 @@ class FigChooser extends HTMLElement {
15332
15238
  this.#syncOverflow();
15333
15239
  });
15334
15240
  this.#resizeObserver.observe(this);
15335
- if (this.#scroller) this.#resizeObserver.observe(this.#scroller);
15336
15241
  }
15337
15242
 
15338
15243
  #setupDrag() {
15339
15244
  if (this.#dragState?.bound) return;
15340
15245
  if (!this.#dragEnabled) return;
15341
- const scrollEl = this.#scrollElement;
15342
15246
 
15343
15247
  const onPointerDown = (e) => {
15344
15248
  if (e.button !== 0) return;
15249
+ if (e.target.closest("[data-fig-chooser-nav]")) return;
15345
15250
  const isHorizontal = this.getAttribute("layout") === "horizontal";
15346
15251
  const hasOverflow = isHorizontal
15347
- ? scrollEl.scrollWidth > scrollEl.clientWidth
15348
- : scrollEl.scrollHeight > scrollEl.clientHeight;
15252
+ ? this.scrollWidth > this.clientWidth
15253
+ : this.scrollHeight > this.clientHeight;
15349
15254
  if (!hasOverflow) return;
15350
15255
 
15351
15256
  this.#dragState.active = true;
15352
15257
  this.#dragState.didDrag = false;
15353
15258
  this.#dragState.startX = e.clientX;
15354
15259
  this.#dragState.startY = e.clientY;
15355
- this.#dragState.scrollLeft = scrollEl.scrollLeft;
15356
- this.#dragState.scrollTop = scrollEl.scrollTop;
15357
- scrollEl.style.cursor = "grab";
15358
- scrollEl.style.userSelect = "none";
15260
+ this.#dragState.scrollLeft = this.scrollLeft;
15261
+ this.#dragState.scrollTop = this.scrollTop;
15262
+ this.style.cursor = "grab";
15263
+ this.style.userSelect = "none";
15359
15264
  };
15360
15265
 
15361
15266
  const onPointerMove = (e) => {
@@ -15366,16 +15271,16 @@ class FigChooser extends HTMLElement {
15366
15271
 
15367
15272
  if (!this.#dragState.didDrag && Math.abs(isHorizontal ? dx : dy) > 3) {
15368
15273
  this.#dragState.didDrag = true;
15369
- scrollEl.style.cursor = "grabbing";
15370
- scrollEl.setPointerCapture(e.pointerId);
15274
+ this.style.cursor = "grabbing";
15275
+ this.setPointerCapture(e.pointerId);
15371
15276
  }
15372
15277
 
15373
15278
  if (!this.#dragState.didDrag) return;
15374
15279
 
15375
15280
  if (isHorizontal) {
15376
- scrollEl.scrollLeft = this.#dragState.scrollLeft - dx;
15281
+ this.scrollLeft = this.#dragState.scrollLeft - dx;
15377
15282
  } else {
15378
- scrollEl.scrollTop = this.#dragState.scrollTop - dy;
15283
+ this.scrollTop = this.#dragState.scrollTop - dy;
15379
15284
  }
15380
15285
  };
15381
15286
 
@@ -15384,11 +15289,11 @@ class FigChooser extends HTMLElement {
15384
15289
  const wasDrag = this.#dragState.didDrag;
15385
15290
  this.#dragState.active = false;
15386
15291
  this.#dragState.didDrag = false;
15387
- scrollEl.style.cursor = "";
15388
- scrollEl.style.userSelect = "";
15292
+ this.style.cursor = "";
15293
+ this.style.userSelect = "";
15389
15294
  if (e.pointerId !== undefined) {
15390
15295
  try {
15391
- scrollEl.releasePointerCapture(e.pointerId);
15296
+ this.releasePointerCapture(e.pointerId);
15392
15297
  } catch {}
15393
15298
  }
15394
15299
  if (wasDrag) {
@@ -15428,10 +15333,9 @@ class FigChooser extends HTMLElement {
15428
15333
  onPointerUp,
15429
15334
  onClick,
15430
15335
  onPointerUpCapture,
15431
- scrollEl,
15432
15336
  };
15433
15337
 
15434
- scrollEl.addEventListener("pointerdown", onPointerDown);
15338
+ this.addEventListener("pointerdown", onPointerDown);
15435
15339
  window.addEventListener("pointermove", onPointerMove);
15436
15340
  window.addEventListener("pointerup", onPointerUp);
15437
15341
  this.addEventListener("pointerup", onPointerUpCapture, true);
@@ -15440,7 +15344,7 @@ class FigChooser extends HTMLElement {
15440
15344
 
15441
15345
  #teardownDrag() {
15442
15346
  if (!this.#dragState?.bound) return;
15443
- this.#dragState.scrollEl.removeEventListener("pointerdown", this.#dragState.onPointerDown);
15347
+ this.removeEventListener("pointerdown", this.#dragState.onPointerDown);
15444
15348
  window.removeEventListener("pointermove", this.#dragState.onPointerMove);
15445
15349
  window.removeEventListener("pointerup", this.#dragState.onPointerUp);
15446
15350
  this.removeEventListener(
@@ -15449,52 +15353,26 @@ class FigChooser extends HTMLElement {
15449
15353
  true,
15450
15354
  );
15451
15355
  this.removeEventListener("click", this.#dragState.onClick, true);
15452
- this.#dragState.scrollEl.style.cursor = "";
15453
- this.#dragState.scrollEl.style.userSelect = "";
15356
+ this.style.cursor = "";
15357
+ this.style.userSelect = "";
15454
15358
  this.#dragState = null;
15455
15359
  }
15456
15360
 
15457
- #ensureScroller() {
15458
- if (this.#isStructuring) return;
15459
- const existing = this.querySelector(":scope > [data-fig-chooser-scroll]");
15460
- if (existing && existing === this.#scroller) return;
15361
+ #removeLegacyScroller() {
15362
+ if (this.#isUnwrapping) return;
15363
+ const legacy = this.querySelector(":scope > [data-fig-chooser-scroll]");
15364
+ if (!legacy) return;
15461
15365
 
15462
- this.#isStructuring = true;
15366
+ this.#isUnwrapping = true;
15463
15367
  try {
15464
- const previousScroller = this.#scroller;
15465
- if (previousScroller && previousScroller !== existing) {
15466
- previousScroller.removeEventListener("scroll", this.#boundSyncOverflow);
15467
- }
15468
-
15469
- const scroller = existing || document.createElement("div");
15470
- scroller.className = "fig-chooser-scroll";
15471
- scroller.dataset.figChooserScroll = "";
15472
-
15473
- const nodes = Array.from(this.childNodes).filter((node) => {
15474
- if (node === scroller) return false;
15475
- if (node.nodeType !== Node.ELEMENT_NODE) return true;
15476
- return !node.hasAttribute("data-fig-chooser-nav");
15477
- });
15478
-
15479
- for (const node of nodes) {
15480
- scroller.appendChild(node);
15481
- }
15482
-
15483
- if (!existing) {
15484
- this.prepend(scroller);
15485
- }
15486
-
15487
- this.#scroller = scroller;
15488
- this.#scroller.removeEventListener("scroll", this.#boundSyncOverflow);
15489
- this.#scroller.addEventListener("scroll", this.#boundSyncOverflow);
15490
- if (this.#resizeObserver) this.#resizeObserver.observe(this.#scroller);
15368
+ const nodes = Array.from(legacy.childNodes);
15369
+ legacy.replaceWith(...nodes);
15491
15370
  } finally {
15492
- this.#isStructuring = false;
15371
+ this.#isUnwrapping = false;
15493
15372
  }
15494
15373
  }
15495
15374
 
15496
15375
  #applyOverflowMode() {
15497
- this.#ensureScroller();
15498
15376
  if (this.#overflowMode === "scrollbar") {
15499
15377
  this.#removeNavButtons();
15500
15378
  } else {
@@ -15542,47 +15420,87 @@ class FigChooser extends HTMLElement {
15542
15420
 
15543
15421
  #scrollByPage(direction) {
15544
15422
  const isHorizontal = this.getAttribute("layout") === "horizontal";
15545
- const scrollEl = this.#scrollElement;
15546
- figScrollOverflowPage(scrollEl, isHorizontal ? "x" : "y", direction);
15423
+ figScrollOverflowPage(this, isHorizontal ? "x" : "y", direction);
15547
15424
  }
15548
15425
 
15549
15426
  #scrollToChoice(el, behavior = "smooth") {
15550
15427
  if (!el) return;
15551
15428
  requestAnimationFrame(() => {
15552
15429
  if (!el.isConnected) return;
15553
- const scrollEl = this.#scrollElement;
15554
- const overflowY = scrollEl.scrollHeight > scrollEl.clientHeight;
15555
- const overflowX = scrollEl.scrollWidth > scrollEl.clientWidth;
15430
+ const overflowY = this.scrollHeight > this.clientHeight;
15431
+ const overflowX = this.scrollWidth > this.clientWidth;
15556
15432
  if (!overflowX && !overflowY) return;
15557
15433
 
15558
15434
  const choiceRect = el.getBoundingClientRect();
15559
- const hostRect = scrollEl.getBoundingClientRect();
15435
+ const hostRect = this.getBoundingClientRect();
15560
15436
  const options = { behavior };
15437
+ let shouldScroll = false;
15438
+ const threshold = 2;
15561
15439
 
15562
15440
  if (overflowY) {
15563
- const choiceCenter =
15564
- choiceRect.top - hostRect.top + scrollEl.scrollTop + choiceRect.height / 2;
15565
- options.top = choiceCenter - scrollEl.clientHeight / 2;
15441
+ const fullyVisible =
15442
+ choiceRect.top >= hostRect.top - 1 &&
15443
+ choiceRect.bottom <= hostRect.bottom + 1;
15444
+ const topVisible = choiceRect.top >= hostRect.top - 1;
15445
+ const bottomVisible = choiceRect.bottom <= hostRect.bottom + 1;
15446
+ const atScrollStart = this.scrollTop <= threshold;
15447
+ const needsScroll =
15448
+ !fullyVisible &&
15449
+ (!topVisible ||
15450
+ (!bottomVisible && !atScrollStart) ||
15451
+ choiceRect.top >= hostRect.bottom - 1);
15452
+ if (needsScroll) {
15453
+ const choiceTop = choiceRect.top - hostRect.top + this.scrollTop;
15454
+ const maxScroll = this.scrollHeight - this.clientHeight;
15455
+ options.top = Math.max(
15456
+ 0,
15457
+ Math.min(
15458
+ choiceTop + choiceRect.height / 2 - this.clientHeight / 2,
15459
+ maxScroll,
15460
+ ),
15461
+ );
15462
+ shouldScroll = true;
15463
+ }
15566
15464
  }
15567
15465
 
15568
15466
  if (overflowX) {
15569
- const choiceCenter =
15570
- choiceRect.left -
15571
- hostRect.left +
15572
- scrollEl.scrollLeft +
15573
- choiceRect.width / 2;
15574
- options.left = choiceCenter - scrollEl.clientWidth / 2;
15467
+ const fullyVisible =
15468
+ choiceRect.left >= hostRect.left - 1 &&
15469
+ choiceRect.right <= hostRect.right + 1;
15470
+ const startVisible = choiceRect.left >= hostRect.left - 1;
15471
+ const endVisible = choiceRect.right <= hostRect.right + 1;
15472
+ const atScrollStart = this.scrollLeft <= threshold;
15473
+ const needsScroll =
15474
+ !fullyVisible &&
15475
+ (!startVisible ||
15476
+ (!endVisible && !atScrollStart) ||
15477
+ choiceRect.left >= hostRect.right - 1);
15478
+ if (needsScroll) {
15479
+ const choiceLeft = choiceRect.left - hostRect.left + this.scrollLeft;
15480
+ const maxScroll = this.scrollWidth - this.clientWidth;
15481
+ options.left = Math.max(
15482
+ 0,
15483
+ Math.min(
15484
+ choiceLeft + choiceRect.width / 2 - this.clientWidth / 2,
15485
+ maxScroll,
15486
+ ),
15487
+ );
15488
+ shouldScroll = true;
15489
+ }
15575
15490
  }
15576
15491
 
15577
- scrollEl.scrollTo(options);
15492
+ if (shouldScroll) {
15493
+ this.scrollTo(options);
15494
+ }
15495
+ this.#syncOverflow();
15578
15496
  });
15579
15497
  }
15580
15498
 
15581
15499
  #startObserver() {
15582
15500
  this.#mutationObserver?.disconnect();
15583
15501
  this.#mutationObserver = new MutationObserver(() => {
15584
- if (this.#isStructuring) return;
15585
- this.#ensureScroller();
15502
+ if (this.#isUnwrapping) return;
15503
+ this.#removeLegacyScroller();
15586
15504
  this.#applyOverflowMode();
15587
15505
  const choices = this.choices;
15588
15506
  if (this.#selectedChoice && !choices.includes(this.#selectedChoice)) {
@@ -15593,7 +15511,7 @@ class FigChooser extends HTMLElement {
15593
15511
  }
15594
15512
  requestAnimationFrame(() => this.#syncOverflow());
15595
15513
  });
15596
- this.#mutationObserver.observe(this, { childList: true, subtree: true });
15514
+ this.#mutationObserver.observe(this, { childList: true, subtree: false });
15597
15515
  }
15598
15516
  }
15599
15517
  customElements.define("fig-chooser", FigChooser);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "6.7.1",
3
+ "version": "6.7.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",