@rogieking/figui3 1.3.0 → 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 +1 -0
- package/fig.css +6 -0
- package/fig.js +56 -29
- package/package.json +1 -1
package/example.html
CHANGED
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
|
|
1732
|
+
this.#render();
|
|
1733
1733
|
|
|
1734
|
-
this
|
|
1734
|
+
this.#setupListeners();
|
|
1735
1735
|
|
|
1736
|
-
this
|
|
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,31 +1785,33 @@ 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
|
|
1787
|
-
window.addEventListener("keydown", this
|
|
1788
|
-
window.addEventListener("keyup", 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
|
|
1791
|
-
this.yInput.addEventListener("input", 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
|
-
this.position.x = e.target.value;
|
|
1798
|
+
this.position.x = Number(e.target.value);
|
|
1799
|
+
this.value = [this.position.x, this.position.y];
|
|
1797
1800
|
this.#syncHandlePosition();
|
|
1798
1801
|
this.#emitInputEvent();
|
|
1799
1802
|
this.#emitChangeEvent();
|
|
1800
1803
|
}
|
|
1801
1804
|
|
|
1802
|
-
handleYInput(e) {
|
|
1805
|
+
#handleYInput(e) {
|
|
1803
1806
|
e.stopPropagation();
|
|
1804
|
-
this.position.y = e.target.value;
|
|
1807
|
+
this.position.y = Number(e.target.value);
|
|
1808
|
+
this.value = [this.position.x, this.position.y];
|
|
1805
1809
|
this.#syncHandlePosition();
|
|
1806
1810
|
this.#emitInputEvent();
|
|
1807
1811
|
this.#emitChangeEvent();
|
|
1808
1812
|
}
|
|
1809
1813
|
|
|
1810
|
-
snapToGuide(value) {
|
|
1814
|
+
#snapToGuide(value) {
|
|
1811
1815
|
if (!this.isShiftHeld) return value;
|
|
1812
1816
|
if (value < 0.1) return 0;
|
|
1813
1817
|
if (value > 0.9) return 1;
|
|
@@ -1815,7 +1819,7 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1815
1819
|
return value;
|
|
1816
1820
|
}
|
|
1817
1821
|
|
|
1818
|
-
snapToDiagonal(x, y) {
|
|
1822
|
+
#snapToDiagonal(x, y) {
|
|
1819
1823
|
if (!this.isShiftHeld) return { x, y };
|
|
1820
1824
|
const diff = Math.abs(x - y);
|
|
1821
1825
|
if (diff < 0.1) return { x: (x + y) / 2, y: (x + y) / 2 };
|
|
@@ -1828,13 +1832,10 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1828
1832
|
let x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
1829
1833
|
let y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
|
|
1830
1834
|
|
|
1831
|
-
|
|
1832
|
-
y =
|
|
1835
|
+
x = this.#snapToGuide(x);
|
|
1836
|
+
y = this.#snapToGuide(y);
|
|
1833
1837
|
|
|
1834
|
-
|
|
1835
|
-
y = this.snapToGuide(y);
|
|
1836
|
-
|
|
1837
|
-
const snapped = this.snapToDiagonal(x, y);
|
|
1838
|
+
const snapped = this.#snapToDiagonal(x, y);
|
|
1838
1839
|
this.position = snapped;
|
|
1839
1840
|
this.value = [snapped.x, snapped.y];
|
|
1840
1841
|
|
|
@@ -1866,12 +1867,15 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1866
1867
|
}
|
|
1867
1868
|
|
|
1868
1869
|
#syncHandlePosition() {
|
|
1869
|
-
this.cursor
|
|
1870
|
-
|
|
1870
|
+
if (this.cursor) {
|
|
1871
|
+
this.cursor.style.left = `${this.position.x * 100}%`;
|
|
1872
|
+
this.cursor.style.top = `${this.position.y * 100}%`;
|
|
1873
|
+
}
|
|
1871
1874
|
}
|
|
1872
1875
|
|
|
1873
|
-
handleMouseDown(e) {
|
|
1876
|
+
#handleMouseDown(e) {
|
|
1874
1877
|
this.isDragging = true;
|
|
1878
|
+
this.plane.classList.add("dragging");
|
|
1875
1879
|
this.#updatePosition(e);
|
|
1876
1880
|
|
|
1877
1881
|
this.plane.style.cursor = "grabbing";
|
|
@@ -1882,6 +1886,7 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1882
1886
|
|
|
1883
1887
|
const handleMouseUp = () => {
|
|
1884
1888
|
this.isDragging = false;
|
|
1889
|
+
this.plane.classList.remove("dragging");
|
|
1885
1890
|
this.plane.style.cursor = "";
|
|
1886
1891
|
window.removeEventListener("mousemove", handleMouseMove);
|
|
1887
1892
|
window.removeEventListener("mouseup", handleMouseUp);
|
|
@@ -1892,13 +1897,35 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1892
1897
|
window.addEventListener("mouseup", handleMouseUp);
|
|
1893
1898
|
}
|
|
1894
1899
|
|
|
1895
|
-
handleKeyDown(e) {
|
|
1900
|
+
#handleKeyDown(e) {
|
|
1896
1901
|
if (e.key === "Shift") this.isShiftHeld = true;
|
|
1897
1902
|
}
|
|
1898
1903
|
|
|
1899
|
-
handleKeyUp(e) {
|
|
1904
|
+
#handleKeyUp(e) {
|
|
1900
1905
|
if (e.key === "Shift") this.isShiftHeld = false;
|
|
1901
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
|
+
}
|
|
1902
1929
|
}
|
|
1903
1930
|
|
|
1904
1931
|
customElements.define("fig-input-joystick", FigInputJoystick);
|