@rogieking/figui3 1.3.1 → 1.3.2

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/example.html CHANGED
@@ -24,6 +24,7 @@
24
24
  </fig-header>
25
25
  <fig-content>
26
26
  <fig-input-joystick text="true"
27
+ value="0,0"
27
28
  onInput="console.log(event.target.value)"></fig-input-joystick>
28
29
  <fig-header>
29
30
  <h2>Details</h2>
package/fig.css CHANGED
@@ -2284,6 +2284,10 @@ fig-input-joystick {
2284
2284
  width: 1.5rem;
2285
2285
  height: 1.5rem;
2286
2286
  place-items: center;
2287
+ flex-shrink: 0;
2288
+ flex-grow: 0;
2289
+ align-items: center;
2290
+ justify-content: center;
2287
2291
  }
2288
2292
  .fig-input-joystick-plane {
2289
2293
  display: inline-grid;
@@ -2292,6 +2296,7 @@ fig-input-joystick {
2292
2296
  width: var(--size);
2293
2297
  height: var(--size);
2294
2298
  flex-shrink: 0;
2299
+ &.dragging,
2295
2300
  &:hover {
2296
2301
  cursor: grab;
2297
2302
  --size: 3rem;
@@ -2330,6 +2335,7 @@ fig-input-joystick {
2330
2335
  pointer-events: none;
2331
2336
  }
2332
2337
  }
2338
+ .fig-input-joystick-plane.dragging .fig-input-joystick-guides,
2333
2339
  .fig-input-joystick-plane:hover .fig-input-joystick-guides {
2334
2340
  background: linear-gradient(
2335
2341
  45deg,
package/fig.js CHANGED
@@ -1729,12 +1729,11 @@ class FigInputJoystick extends HTMLElement {
1729
1729
  this.transform = Number(this.transform);
1730
1730
  this.text = this.getAttribute("text") === "true";
1731
1731
 
1732
- this.render();
1732
+ this.#render();
1733
1733
 
1734
- this.setupListeners();
1734
+ this.#setupListeners();
1735
1735
 
1736
- this.cursor.style.left = `${this.position.x * 100}%`;
1737
- this.cursor.style.top = `${this.position.y * 100}%`;
1736
+ this.#syncHandlePosition();
1738
1737
  if (this.text) {
1739
1738
  this.xInput.value = this.position.x.toFixed(this.precision);
1740
1739
  this.yInput.value = this.position.y.toFixed(this.precision);
@@ -1742,8 +1741,11 @@ class FigInputJoystick extends HTMLElement {
1742
1741
  });
1743
1742
  }
1744
1743
 
1745
- render() {
1746
- this.innerHTML = `
1744
+ #render() {
1745
+ this.innerHTML = this.#getInnerHTML();
1746
+ }
1747
+ #getInnerHTML() {
1748
+ return `
1747
1749
  <div class="fig-input-joystick-plane-container">
1748
1750
  <div class="fig-input-joystick-plane">
1749
1751
  <div class="fig-input-joystick-guides"></div>
@@ -1775,7 +1777,7 @@ class FigInputJoystick extends HTMLElement {
1775
1777
  `;
1776
1778
  }
1777
1779
 
1778
- setupListeners() {
1780
+ #setupListeners() {
1779
1781
  this.plane = this.querySelector(".fig-input-joystick-plane");
1780
1782
  this.cursor = this.querySelector(".fig-input-joystick-handle");
1781
1783
  if (this.text) {
@@ -1783,15 +1785,15 @@ class FigInputJoystick extends HTMLElement {
1783
1785
  this.yInput = this.querySelector("fig-input-text[name='y']");
1784
1786
  }
1785
1787
 
1786
- this.plane.addEventListener("mousedown", this.handleMouseDown.bind(this));
1787
- window.addEventListener("keydown", this.handleKeyDown.bind(this));
1788
- window.addEventListener("keyup", this.handleKeyUp.bind(this));
1788
+ this.plane.addEventListener("mousedown", this.#handleMouseDown.bind(this));
1789
+ window.addEventListener("keydown", this.#handleKeyDown.bind(this));
1790
+ window.addEventListener("keyup", this.#handleKeyUp.bind(this));
1789
1791
 
1790
- this.xInput.addEventListener("input", this.handleXInput.bind(this));
1791
- this.yInput.addEventListener("input", this.handleYInput.bind(this));
1792
+ this.xInput.addEventListener("input", this.#handleXInput.bind(this));
1793
+ this.yInput.addEventListener("input", this.#handleYInput.bind(this));
1792
1794
  }
1793
1795
 
1794
- handleXInput(e) {
1796
+ #handleXInput(e) {
1795
1797
  e.stopPropagation();
1796
1798
  this.position.x = Number(e.target.value);
1797
1799
  this.value = [this.position.x, this.position.y];
@@ -1800,7 +1802,7 @@ class FigInputJoystick extends HTMLElement {
1800
1802
  this.#emitChangeEvent();
1801
1803
  }
1802
1804
 
1803
- handleYInput(e) {
1805
+ #handleYInput(e) {
1804
1806
  e.stopPropagation();
1805
1807
  this.position.y = Number(e.target.value);
1806
1808
  this.value = [this.position.x, this.position.y];
@@ -1809,7 +1811,7 @@ class FigInputJoystick extends HTMLElement {
1809
1811
  this.#emitChangeEvent();
1810
1812
  }
1811
1813
 
1812
- snapToGuide(value) {
1814
+ #snapToGuide(value) {
1813
1815
  if (!this.isShiftHeld) return value;
1814
1816
  if (value < 0.1) return 0;
1815
1817
  if (value > 0.9) return 1;
@@ -1817,7 +1819,7 @@ class FigInputJoystick extends HTMLElement {
1817
1819
  return value;
1818
1820
  }
1819
1821
 
1820
- snapToDiagonal(x, y) {
1822
+ #snapToDiagonal(x, y) {
1821
1823
  if (!this.isShiftHeld) return { x, y };
1822
1824
  const diff = Math.abs(x - y);
1823
1825
  if (diff < 0.1) return { x: (x + y) / 2, y: (x + y) / 2 };
@@ -1830,13 +1832,10 @@ class FigInputJoystick extends HTMLElement {
1830
1832
  let x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
1831
1833
  let y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
1832
1834
 
1833
- // Invert Y coordinate to match typical coordinate system
1834
- y = 1 - y;
1835
+ x = this.#snapToGuide(x);
1836
+ y = this.#snapToGuide(y);
1835
1837
 
1836
- x = this.snapToGuide(x);
1837
- y = this.snapToGuide(y);
1838
-
1839
- const snapped = this.snapToDiagonal(x, y);
1838
+ const snapped = this.#snapToDiagonal(x, y);
1840
1839
  this.position = snapped;
1841
1840
  this.value = [snapped.x, snapped.y];
1842
1841
 
@@ -1868,12 +1867,15 @@ class FigInputJoystick extends HTMLElement {
1868
1867
  }
1869
1868
 
1870
1869
  #syncHandlePosition() {
1871
- this.cursor.style.left = `${this.position.x * 100}%`;
1872
- this.cursor.style.top = `${(1 - this.position.y) * 100}%`;
1870
+ if (this.cursor) {
1871
+ this.cursor.style.left = `${this.position.x * 100}%`;
1872
+ this.cursor.style.top = `${this.position.y * 100}%`;
1873
+ }
1873
1874
  }
1874
1875
 
1875
- handleMouseDown(e) {
1876
+ #handleMouseDown(e) {
1876
1877
  this.isDragging = true;
1878
+ this.plane.classList.add("dragging");
1877
1879
  this.#updatePosition(e);
1878
1880
 
1879
1881
  this.plane.style.cursor = "grabbing";
@@ -1884,6 +1886,7 @@ class FigInputJoystick extends HTMLElement {
1884
1886
 
1885
1887
  const handleMouseUp = () => {
1886
1888
  this.isDragging = false;
1889
+ this.plane.classList.remove("dragging");
1887
1890
  this.plane.style.cursor = "";
1888
1891
  window.removeEventListener("mousemove", handleMouseMove);
1889
1892
  window.removeEventListener("mouseup", handleMouseUp);
@@ -1894,13 +1897,35 @@ class FigInputJoystick extends HTMLElement {
1894
1897
  window.addEventListener("mouseup", handleMouseUp);
1895
1898
  }
1896
1899
 
1897
- handleKeyDown(e) {
1900
+ #handleKeyDown(e) {
1898
1901
  if (e.key === "Shift") this.isShiftHeld = true;
1899
1902
  }
1900
1903
 
1901
- handleKeyUp(e) {
1904
+ #handleKeyUp(e) {
1902
1905
  if (e.key === "Shift") this.isShiftHeld = false;
1903
1906
  }
1907
+ static get observedAttributes() {
1908
+ return ["value", "precision", "transform", "text"];
1909
+ }
1910
+ attributeChangedCallback(name, oldValue, newValue) {
1911
+ if (name === "value") {
1912
+ this.value = newValue.split(",").map(Number);
1913
+ this.position = { x: this.value[0], y: this.value[1] };
1914
+ this.#syncHandlePosition();
1915
+ }
1916
+ if (name === "precision") {
1917
+ this.precision = newValue;
1918
+ this.precision = parseInt(this.precision);
1919
+ }
1920
+ if (name === "transform") {
1921
+ this.transform = newValue;
1922
+ this.transform = Number(this.transform);
1923
+ }
1924
+ if (name === "text") {
1925
+ this.text = newValue.toLowerCase() === "true";
1926
+ this.innerHTML = this.#getInnerHTML();
1927
+ }
1928
+ }
1904
1929
  }
1905
1930
 
1906
1931
  customElements.define("fig-input-joystick", FigInputJoystick);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {