@rogieking/figui3 1.3.3 → 1.3.4
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 -1
- package/fig.css +19 -9
- package/fig.js +35 -2
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<fig-content>
|
|
26
26
|
<fig-input-angle text="true"
|
|
27
27
|
value="0"
|
|
28
|
-
onInput="console.log(event.target.
|
|
28
|
+
onInput="console.log(event.target.adjacent, event.target.opposite)"></fig-input-angle>
|
|
29
29
|
<br /><br />
|
|
30
30
|
<fig-input-joystick></fig-input-joystick>
|
|
31
31
|
<br /><br />
|
package/fig.css
CHANGED
|
@@ -415,7 +415,7 @@
|
|
|
415
415
|
--body-medium-fontWeight: 450;
|
|
416
416
|
--handle-shadow: 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
|
|
417
417
|
0px 1px 3px 0px rgba(0, 0, 0, 0.05), 0px 3px 8px 0px rgba(0, 0, 0, 0.05),
|
|
418
|
-
0px 0px 0.5px 0px rgba(0, 0, 0, 0.1);
|
|
418
|
+
0px 0px 0.5px 0px rgba(0, 0, 0, 0.1), var(--figma-elevation-200);
|
|
419
419
|
|
|
420
420
|
--popover-min-width: 15rem;
|
|
421
421
|
--figma-color-bg-ghost-hover: rgba(0, 0, 0, 0.05);
|
|
@@ -2267,6 +2267,7 @@ fig-input-joystick {
|
|
|
2267
2267
|
--size: 1.5rem;
|
|
2268
2268
|
display: inline-flex;
|
|
2269
2269
|
gap: var(--spacer-2);
|
|
2270
|
+
user-select: none;
|
|
2270
2271
|
.fig-input-joystick-plane-container {
|
|
2271
2272
|
display: flex;
|
|
2272
2273
|
width: 1.5rem;
|
|
@@ -2276,6 +2277,9 @@ fig-input-joystick {
|
|
|
2276
2277
|
flex-grow: 0;
|
|
2277
2278
|
align-items: center;
|
|
2278
2279
|
justify-content: center;
|
|
2280
|
+
&:focus {
|
|
2281
|
+
outline: 0;
|
|
2282
|
+
}
|
|
2279
2283
|
}
|
|
2280
2284
|
.fig-input-joystick-plane {
|
|
2281
2285
|
display: inline-grid;
|
|
@@ -2297,7 +2301,7 @@ fig-input-joystick {
|
|
|
2297
2301
|
position: absolute;
|
|
2298
2302
|
width: var(--size);
|
|
2299
2303
|
height: var(--size);
|
|
2300
|
-
|
|
2304
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-border);
|
|
2301
2305
|
border-radius: var(--radius-medium);
|
|
2302
2306
|
overflow: hidden;
|
|
2303
2307
|
background: var(--figma-color-bg-secondary);
|
|
@@ -2307,8 +2311,8 @@ fig-input-joystick {
|
|
|
2307
2311
|
position: absolute;
|
|
2308
2312
|
height: 0;
|
|
2309
2313
|
border-left: 1px solid var(--figma-color-border);
|
|
2310
|
-
height: 100
|
|
2311
|
-
top:
|
|
2314
|
+
height: calc(100% - 2px);
|
|
2315
|
+
top: 1px;
|
|
2312
2316
|
left: calc(50% - 0.5px);
|
|
2313
2317
|
pointer-events: none;
|
|
2314
2318
|
}
|
|
@@ -2317,9 +2321,9 @@ fig-input-joystick {
|
|
|
2317
2321
|
position: absolute;
|
|
2318
2322
|
height: 0;
|
|
2319
2323
|
border-top: 1px solid var(--figma-color-border);
|
|
2320
|
-
width: 100
|
|
2324
|
+
width: calc(100% - 2px);
|
|
2321
2325
|
top: calc(50% - 0.5px);
|
|
2322
|
-
left:
|
|
2326
|
+
left: 1px;
|
|
2323
2327
|
pointer-events: none;
|
|
2324
2328
|
}
|
|
2325
2329
|
}
|
|
@@ -2339,7 +2343,12 @@ fig-input-joystick {
|
|
|
2339
2343
|
transparent calc(50% + 0.5px)
|
|
2340
2344
|
),
|
|
2341
2345
|
var(--figma-color-bg-secondary);
|
|
2346
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-border-selected);
|
|
2342
2347
|
}
|
|
2348
|
+
.fig-input-joystick-plane-container:focus .fig-input-joystick-guides {
|
|
2349
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-border-selected);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2343
2352
|
.fig-input-joystick-handle {
|
|
2344
2353
|
position: absolute;
|
|
2345
2354
|
z-index: 1;
|
|
@@ -2356,6 +2365,7 @@ fig-input-angle {
|
|
|
2356
2365
|
--size: 1.5rem;
|
|
2357
2366
|
display: inline-flex;
|
|
2358
2367
|
gap: var(--spacer-2);
|
|
2368
|
+
user-select: none;
|
|
2359
2369
|
|
|
2360
2370
|
.fig-input-angle-plane {
|
|
2361
2371
|
display: inline-grid;
|
|
@@ -2367,10 +2377,10 @@ fig-input-angle {
|
|
|
2367
2377
|
background-color: var(--figma-color-bg-secondary);
|
|
2368
2378
|
border-radius: 100%;
|
|
2369
2379
|
box-shadow: inset 0 0 0 1px var(--figma-color-border);
|
|
2380
|
+
&:focus,
|
|
2370
2381
|
&.dragging {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
z-index: 2;
|
|
2382
|
+
outline: 0;
|
|
2383
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-border-selected);
|
|
2374
2384
|
}
|
|
2375
2385
|
}
|
|
2376
2386
|
.fig-input-angle-handle {
|
package/fig.js
CHANGED
|
@@ -1767,7 +1767,7 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1767
1767
|
}
|
|
1768
1768
|
#getInnerHTML() {
|
|
1769
1769
|
return `
|
|
1770
|
-
<div class="fig-input-joystick-plane-container">
|
|
1770
|
+
<div class="fig-input-joystick-plane-container" tabindex="0">
|
|
1771
1771
|
<div class="fig-input-joystick-plane">
|
|
1772
1772
|
<div class="fig-input-joystick-guides"></div>
|
|
1773
1773
|
<div class="fig-input-joystick-handle"></div>
|
|
@@ -1801,6 +1801,8 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1801
1801
|
#setupListeners() {
|
|
1802
1802
|
this.plane = this.querySelector(".fig-input-joystick-plane");
|
|
1803
1803
|
this.cursor = this.querySelector(".fig-input-joystick-handle");
|
|
1804
|
+
this.xInput = this.querySelector("fig-input-text[name='x']");
|
|
1805
|
+
this.yInput = this.querySelector("fig-input-text[name='y']");
|
|
1804
1806
|
this.plane.addEventListener("mousedown", this.#handleMouseDown.bind(this));
|
|
1805
1807
|
this.plane.addEventListener(
|
|
1806
1808
|
"touchstart",
|
|
@@ -1938,6 +1940,7 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1938
1940
|
|
|
1939
1941
|
const handleTouchEnd = () => {
|
|
1940
1942
|
this.isDragging = false;
|
|
1943
|
+
this.plane.classList.remove("dragging");
|
|
1941
1944
|
window.removeEventListener("touchmove", handleTouchMove);
|
|
1942
1945
|
window.removeEventListener("touchend", handleTouchEnd);
|
|
1943
1946
|
this.#emitChangeEvent();
|
|
@@ -1989,12 +1992,20 @@ customElements.define("fig-input-joystick", FigInputJoystick);
|
|
|
1989
1992
|
* @attr {number} value - The current angle of the handle in degrees.
|
|
1990
1993
|
* @attr {number} precision - The number of decimal places for the output.
|
|
1991
1994
|
* @attr {boolean} text - Whether to display a text input for the angle value.
|
|
1995
|
+
* @attr {number} adjacent - The adjacent value of the angle.
|
|
1996
|
+
* @attr {number} opposite - The opposite value of the angle.
|
|
1992
1997
|
*/
|
|
1993
1998
|
class FigInputAngle extends HTMLElement {
|
|
1999
|
+
// Declare private fields first
|
|
2000
|
+
#adjacent;
|
|
2001
|
+
#opposite;
|
|
2002
|
+
|
|
1994
2003
|
constructor() {
|
|
1995
2004
|
super();
|
|
1996
2005
|
|
|
1997
2006
|
this.angle = 0; // Angle in degrees
|
|
2007
|
+
this.#adjacent = 1;
|
|
2008
|
+
this.#opposite = 0;
|
|
1998
2009
|
this.isDragging = false;
|
|
1999
2010
|
this.isShiftHeld = false;
|
|
2000
2011
|
this.handle = null;
|
|
@@ -2031,7 +2042,7 @@ class FigInputAngle extends HTMLElement {
|
|
|
2031
2042
|
|
|
2032
2043
|
#getInnerHTML() {
|
|
2033
2044
|
return `
|
|
2034
|
-
<div class="fig-input-angle-plane">
|
|
2045
|
+
<div class="fig-input-angle-plane" tabindex="0">
|
|
2035
2046
|
<div class="fig-input-angle-handle"></div>
|
|
2036
2047
|
</div>
|
|
2037
2048
|
${
|
|
@@ -2083,11 +2094,18 @@ class FigInputAngle extends HTMLElement {
|
|
|
2083
2094
|
#handleAngleInput(e) {
|
|
2084
2095
|
e.stopPropagation();
|
|
2085
2096
|
this.angle = Number(e.target.value);
|
|
2097
|
+
this.#calculateAdjacentAndOpposite();
|
|
2086
2098
|
this.#syncHandlePosition();
|
|
2087
2099
|
this.#emitInputEvent();
|
|
2088
2100
|
this.#emitChangeEvent();
|
|
2089
2101
|
}
|
|
2090
2102
|
|
|
2103
|
+
#calculateAdjacentAndOpposite() {
|
|
2104
|
+
const radians = (this.angle * Math.PI) / 180;
|
|
2105
|
+
this.#adjacent = Math.cos(radians);
|
|
2106
|
+
this.#opposite = Math.sin(radians);
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2091
2109
|
#snapToIncrement(angle) {
|
|
2092
2110
|
if (!this.isShiftHeld) return angle;
|
|
2093
2111
|
const increment = 45;
|
|
@@ -2105,6 +2123,8 @@ class FigInputAngle extends HTMLElement {
|
|
|
2105
2123
|
angle = this.#snapToIncrement(angle);
|
|
2106
2124
|
this.angle = angle;
|
|
2107
2125
|
|
|
2126
|
+
this.#calculateAdjacentAndOpposite();
|
|
2127
|
+
|
|
2108
2128
|
this.#syncHandlePosition();
|
|
2109
2129
|
if (this.text && this.angleInput) {
|
|
2110
2130
|
this.angleInput.setAttribute("value", this.angle.toFixed(this.precision));
|
|
@@ -2146,11 +2166,13 @@ class FigInputAngle extends HTMLElement {
|
|
|
2146
2166
|
this.#updateAngle(e);
|
|
2147
2167
|
|
|
2148
2168
|
const handleMouseMove = (e) => {
|
|
2169
|
+
this.plane.classList.add("dragging");
|
|
2149
2170
|
if (this.isDragging) this.#updateAngle(e);
|
|
2150
2171
|
};
|
|
2151
2172
|
|
|
2152
2173
|
const handleMouseUp = () => {
|
|
2153
2174
|
this.isDragging = false;
|
|
2175
|
+
this.plane.classList.remove("dragging");
|
|
2154
2176
|
window.removeEventListener("mousemove", handleMouseMove);
|
|
2155
2177
|
window.removeEventListener("mouseup", handleMouseUp);
|
|
2156
2178
|
this.#emitChangeEvent();
|
|
@@ -2166,11 +2188,13 @@ class FigInputAngle extends HTMLElement {
|
|
|
2166
2188
|
this.#updateAngle(e.touches[0]);
|
|
2167
2189
|
|
|
2168
2190
|
const handleTouchMove = (e) => {
|
|
2191
|
+
this.plane.classList.add("dragging");
|
|
2169
2192
|
if (this.isDragging) this.#updateAngle(e.touches[0]);
|
|
2170
2193
|
};
|
|
2171
2194
|
|
|
2172
2195
|
const handleTouchEnd = () => {
|
|
2173
2196
|
this.isDragging = false;
|
|
2197
|
+
this.plane.classList.remove("dragging");
|
|
2174
2198
|
window.removeEventListener("touchmove", handleTouchMove);
|
|
2175
2199
|
window.removeEventListener("touchend", handleTouchEnd);
|
|
2176
2200
|
this.#emitChangeEvent();
|
|
@@ -2196,12 +2220,21 @@ class FigInputAngle extends HTMLElement {
|
|
|
2196
2220
|
return this.angle;
|
|
2197
2221
|
}
|
|
2198
2222
|
|
|
2223
|
+
get adjacent() {
|
|
2224
|
+
return this.#adjacent;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
get opposite() {
|
|
2228
|
+
return this.#opposite;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2199
2231
|
set value(value) {
|
|
2200
2232
|
if (isNaN(value)) {
|
|
2201
2233
|
console.error("Invalid value: must be a number.");
|
|
2202
2234
|
return;
|
|
2203
2235
|
}
|
|
2204
2236
|
this.angle = value;
|
|
2237
|
+
this.#calculateAdjacentAndOpposite();
|
|
2205
2238
|
this.#syncHandlePosition();
|
|
2206
2239
|
}
|
|
2207
2240
|
|