@rogieking/figui3 4.10.2 → 4.12.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.js CHANGED
@@ -14309,7 +14309,6 @@ class FigChooser extends HTMLElement {
14309
14309
  "drag",
14310
14310
  "overflow",
14311
14311
  "loop",
14312
- "padding",
14313
14312
  ];
14314
14313
  }
14315
14314
 
@@ -14380,6 +14379,35 @@ class FigChooser extends HTMLElement {
14380
14379
  requestAnimationFrame(() => {
14381
14380
  this.#syncSelection();
14382
14381
  this.#syncOverflow();
14382
+ this.#scheduleInitialScrollSettle();
14383
+ });
14384
+ }
14385
+
14386
+ #scheduleInitialScrollSettle() {
14387
+ const resettle = () => {
14388
+ if (!this.isConnected) return;
14389
+ if (this.#selectedChoice) {
14390
+ this.#scrollToChoice(this.#selectedChoice, "auto");
14391
+ }
14392
+ };
14393
+ const wireImages = () => {
14394
+ const imgs = this.querySelectorAll("img, video");
14395
+ for (const m of imgs) {
14396
+ if (m.tagName === "IMG" ? m.complete : m.readyState >= 1) continue;
14397
+ const done = () => {
14398
+ m.removeEventListener("load", done);
14399
+ m.removeEventListener("loadedmetadata", done);
14400
+ m.removeEventListener("error", done);
14401
+ resettle();
14402
+ };
14403
+ m.addEventListener("load", done);
14404
+ m.addEventListener("loadedmetadata", done);
14405
+ m.addEventListener("error", done);
14406
+ }
14407
+ };
14408
+ requestAnimationFrame(() => {
14409
+ wireImages();
14410
+ resettle();
14383
14411
  });
14384
14412
  }
14385
14413
 
@@ -14723,22 +14751,32 @@ class FigChooser extends HTMLElement {
14723
14751
  #createNavButtons() {
14724
14752
  if (this.#navStart) return;
14725
14753
 
14754
+ const makeChevron = () => {
14755
+ const icon = document.createElement("span");
14756
+ icon.className = "fig-mask-icon fig-chooser-nav-chevron";
14757
+ icon.style.setProperty("--icon", "var(--icon-chevron)");
14758
+ icon.style.setProperty("--size", "1rem");
14759
+ return icon;
14760
+ };
14761
+
14726
14762
  this.#navStart = document.createElement("button");
14727
14763
  this.#navStart.className = "fig-chooser-nav-start";
14728
14764
  this.#navStart.setAttribute("tabindex", "-1");
14729
14765
  this.#navStart.setAttribute("aria-label", "Scroll back");
14766
+ this.#navStart.appendChild(makeChevron());
14730
14767
 
14731
14768
  this.#navEnd = document.createElement("button");
14732
14769
  this.#navEnd.className = "fig-chooser-nav-end";
14733
14770
  this.#navEnd.setAttribute("tabindex", "-1");
14734
14771
  this.#navEnd.setAttribute("aria-label", "Scroll forward");
14772
+ this.#navEnd.appendChild(makeChevron());
14735
14773
 
14736
- this.#navStart.addEventListener("pointerdown", (e) => {
14774
+ this.#navStart.addEventListener("pointerup", (e) => {
14737
14775
  e.stopPropagation();
14738
14776
  this.#scrollByPage(-1);
14739
14777
  });
14740
14778
 
14741
- this.#navEnd.addEventListener("pointerdown", (e) => {
14779
+ this.#navEnd.addEventListener("pointerup", (e) => {
14742
14780
  e.stopPropagation();
14743
14781
  this.#scrollByPage(1);
14744
14782
  });
@@ -14758,25 +14796,31 @@ class FigChooser extends HTMLElement {
14758
14796
  });
14759
14797
  }
14760
14798
 
14761
- #scrollToChoice(el) {
14799
+ #scrollToChoice(el, behavior = "smooth") {
14762
14800
  if (!el) return;
14763
14801
  requestAnimationFrame(() => {
14802
+ if (!el.isConnected) return;
14764
14803
  const overflowY = this.scrollHeight > this.clientHeight;
14765
14804
  const overflowX = this.scrollWidth > this.clientWidth;
14766
14805
  if (!overflowX && !overflowY) return;
14767
14806
 
14768
- const options = { behavior: "smooth" };
14807
+ const choiceRect = el.getBoundingClientRect();
14808
+ const hostRect = this.getBoundingClientRect();
14809
+ const options = { behavior };
14769
14810
 
14770
14811
  if (overflowY) {
14771
- const target =
14772
- el.offsetTop - this.clientHeight / 2 + el.offsetHeight / 2;
14773
- options.top = target;
14812
+ const choiceCenter =
14813
+ choiceRect.top - hostRect.top + this.scrollTop + choiceRect.height / 2;
14814
+ options.top = choiceCenter - this.clientHeight / 2;
14774
14815
  }
14775
14816
 
14776
14817
  if (overflowX) {
14777
- const target =
14778
- el.offsetLeft - this.clientWidth / 2 + el.offsetWidth / 2;
14779
- options.left = target;
14818
+ const choiceCenter =
14819
+ choiceRect.left -
14820
+ hostRect.left +
14821
+ this.scrollLeft +
14822
+ choiceRect.width / 2;
14823
+ options.left = choiceCenter - this.clientWidth / 2;
14780
14824
  }
14781
14825
 
14782
14826
  this.scrollTo(options);
@@ -15037,6 +15081,7 @@ class FigHandle extends HTMLElement {
15037
15081
  }
15038
15082
 
15039
15083
  connectedCallback() {
15084
+ if (!this.hasAttribute("type")) this.setAttribute("type", "canvas");
15040
15085
  this.#syncDrag();
15041
15086
  this.#syncHitArea();
15042
15087
  this.addEventListener("click", this.#handleSelect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "4.10.2",
3
+ "version": "4.12.0",
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",