@rogieking/figui3 1.0.99 → 1.1.1
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 +7 -3
- package/fig.css +1 -1
- package/fig.js +69 -22
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
<label>Opacity slider</label>
|
|
81
81
|
<fig-slider type="opacity"
|
|
82
82
|
variant="minimal"
|
|
83
|
-
value="
|
|
83
|
+
value="75"
|
|
84
84
|
color="#ff0000"
|
|
85
85
|
units="%"
|
|
86
86
|
text="true"></fig-slider>
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
<fig-field style="width:300px;">
|
|
90
90
|
<label>Hue slider</label>
|
|
91
91
|
<fig-slider type="hue"
|
|
92
|
+
style="--bg-hue: linear-gradient(90deg in lch longer hue,#fc38ff, #abff57)"
|
|
92
93
|
variant="minimal"
|
|
93
94
|
value="55"></fig-slider>
|
|
94
95
|
</fig-field>
|
|
@@ -131,10 +132,11 @@
|
|
|
131
132
|
transform="100"
|
|
132
133
|
type="number"
|
|
133
134
|
autoresize="true"
|
|
134
|
-
value="0.5"
|
|
135
|
-
text="true">
|
|
135
|
+
value="0.5">
|
|
136
136
|
<span slot="append">%</span>
|
|
137
137
|
</fig-input-text>
|
|
138
|
+
|
|
139
|
+
|
|
138
140
|
<br />
|
|
139
141
|
<details>
|
|
140
142
|
<summary>Details</summary>
|
|
@@ -424,6 +426,8 @@
|
|
|
424
426
|
</fig-combo-input>
|
|
425
427
|
<br /><br />
|
|
426
428
|
<fig-input-text type="number"
|
|
429
|
+
min="0"
|
|
430
|
+
max="360"
|
|
427
431
|
value="90">
|
|
428
432
|
<span slot="append">°</span>
|
|
429
433
|
</fig-input-text>
|
package/fig.css
CHANGED
package/fig.js
CHANGED
|
@@ -927,21 +927,17 @@ class FigInputText extends HTMLElement {
|
|
|
927
927
|
#handleInput(e) {
|
|
928
928
|
let value = e.target.value;
|
|
929
929
|
if (this.type === "number") {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
}
|
|
933
|
-
if (this.max) {
|
|
934
|
-
value = Math.max(this.max, value);
|
|
935
|
-
}
|
|
930
|
+
value = this.#sanitizeInput(value);
|
|
931
|
+
//value = Number(value);
|
|
936
932
|
value = value / (this.transform || 1);
|
|
937
933
|
}
|
|
938
|
-
this.value
|
|
934
|
+
this.setAttribute("value", value);
|
|
939
935
|
}
|
|
940
936
|
#handleMouseMove(e) {
|
|
941
937
|
if (e.altKey) {
|
|
942
938
|
const step = (this.step || 1) * e.movementX;
|
|
943
|
-
const value = Number(this.
|
|
944
|
-
this.setAttribute("value", value
|
|
939
|
+
const value = this.#sanitizeInput(Number(this.value) + step).toFixed(2);
|
|
940
|
+
this.setAttribute("value", value);
|
|
945
941
|
}
|
|
946
942
|
}
|
|
947
943
|
#handleMouseDown(e) {
|
|
@@ -950,6 +946,7 @@ class FigInputText extends HTMLElement {
|
|
|
950
946
|
this.style.cursor =
|
|
951
947
|
document.body.style.cursor =
|
|
952
948
|
"ew-resize";
|
|
949
|
+
this.style.userSelect = "none";
|
|
953
950
|
// Use the pre-bound handlers
|
|
954
951
|
window.addEventListener("pointermove", this.#boundMouseMove);
|
|
955
952
|
window.addEventListener("pointerup", this.#boundMouseUp);
|
|
@@ -960,10 +957,24 @@ class FigInputText extends HTMLElement {
|
|
|
960
957
|
this.style.cursor =
|
|
961
958
|
document.body.style.cursor =
|
|
962
959
|
"";
|
|
960
|
+
this.style.userSelect = "all";
|
|
963
961
|
// Remove the pre-bound handlers
|
|
964
962
|
window.removeEventListener("pointermove", this.#boundMouseMove);
|
|
965
963
|
window.removeEventListener("pointerup", this.#boundMouseUp);
|
|
966
964
|
}
|
|
965
|
+
#sanitizeInput(value) {
|
|
966
|
+
let sanitized = value;
|
|
967
|
+
if (this.type === "number") {
|
|
968
|
+
sanitized = Number(sanitized);
|
|
969
|
+
if (typeof this.min === "number") {
|
|
970
|
+
sanitized = Math.max(this.#transformNumber(this.min), sanitized);
|
|
971
|
+
}
|
|
972
|
+
if (typeof this.max === "number") {
|
|
973
|
+
sanitized = Math.min(this.#transformNumber(this.max), sanitized);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return sanitized;
|
|
977
|
+
}
|
|
967
978
|
|
|
968
979
|
static get observedAttributes() {
|
|
969
980
|
return [
|
|
@@ -983,7 +994,9 @@ class FigInputText extends HTMLElement {
|
|
|
983
994
|
if (this.input) {
|
|
984
995
|
switch (name) {
|
|
985
996
|
case "disabled":
|
|
986
|
-
this.disabled = this.input.disabled =
|
|
997
|
+
this.disabled = this.input.disabled =
|
|
998
|
+
newValue === "true" ||
|
|
999
|
+
(newValue === undefined && newValue !== null);
|
|
987
1000
|
break;
|
|
988
1001
|
case "transform":
|
|
989
1002
|
if (this.type === "number") {
|
|
@@ -994,16 +1007,29 @@ class FigInputText extends HTMLElement {
|
|
|
994
1007
|
this.value = this.#transformNumber(this.value);
|
|
995
1008
|
}
|
|
996
1009
|
break;
|
|
997
|
-
|
|
1010
|
+
case "value":
|
|
998
1011
|
let value = newValue;
|
|
999
1012
|
if (this.type === "number") {
|
|
1000
|
-
|
|
1013
|
+
let sanitized = this.#sanitizeInput(value);
|
|
1014
|
+
this.value = sanitized;
|
|
1015
|
+
this.input.value = this.#transformNumber(sanitized);
|
|
1016
|
+
} else {
|
|
1017
|
+
this.value = value;
|
|
1018
|
+
this.input.value = value;
|
|
1001
1019
|
}
|
|
1002
|
-
this
|
|
1020
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1021
|
+
break;
|
|
1022
|
+
case "min":
|
|
1023
|
+
case "max":
|
|
1024
|
+
case "step":
|
|
1025
|
+
this[name] = this.input[name] = Number(newValue);
|
|
1003
1026
|
if (this.input) {
|
|
1004
|
-
this.input.setAttribute(name,
|
|
1027
|
+
this.input.setAttribute(name, newValue);
|
|
1005
1028
|
}
|
|
1006
1029
|
break;
|
|
1030
|
+
default:
|
|
1031
|
+
this[name] = this.input[name] = value;
|
|
1032
|
+
break;
|
|
1007
1033
|
}
|
|
1008
1034
|
}
|
|
1009
1035
|
}
|
|
@@ -1106,7 +1132,7 @@ class FigInputColor extends HTMLElement {
|
|
|
1106
1132
|
);
|
|
1107
1133
|
let html = ``;
|
|
1108
1134
|
if (this.getAttribute("text")) {
|
|
1109
|
-
let label = `<fig-input-text placeholder="Text" value="${this.getAttribute(
|
|
1135
|
+
let label = `<fig-input-text type="text" placeholder="Text" value="${this.getAttribute(
|
|
1110
1136
|
"value"
|
|
1111
1137
|
)}"></fig-input-text>`;
|
|
1112
1138
|
if (this.getAttribute("alpha") === "true") {
|
|
@@ -1134,8 +1160,8 @@ class FigInputColor extends HTMLElement {
|
|
|
1134
1160
|
|
|
1135
1161
|
requestAnimationFrame(() => {
|
|
1136
1162
|
this.#swatch = this.querySelector("input[type=color]");
|
|
1137
|
-
this.textInput = this.querySelector("input[type=
|
|
1138
|
-
this.#alphaInput = this.querySelector("input[type=number]");
|
|
1163
|
+
this.textInput = this.querySelector("fig-input-text:not([type=number])");
|
|
1164
|
+
this.#alphaInput = this.querySelector("fig-input-text[type=number]");
|
|
1139
1165
|
|
|
1140
1166
|
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
1141
1167
|
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
@@ -1145,6 +1171,10 @@ class FigInputColor extends HTMLElement {
|
|
|
1145
1171
|
this.#rgba,
|
|
1146
1172
|
1
|
|
1147
1173
|
);
|
|
1174
|
+
this.textInput.addEventListener(
|
|
1175
|
+
"input",
|
|
1176
|
+
this.#handleTextInput.bind(this)
|
|
1177
|
+
);
|
|
1148
1178
|
}
|
|
1149
1179
|
|
|
1150
1180
|
if (this.#alphaInput) {
|
|
@@ -1155,6 +1185,12 @@ class FigInputColor extends HTMLElement {
|
|
|
1155
1185
|
}
|
|
1156
1186
|
});
|
|
1157
1187
|
}
|
|
1188
|
+
#handleTextInput(event) {
|
|
1189
|
+
//do not propagate to onInput handler for web component
|
|
1190
|
+
event.stopPropagation();
|
|
1191
|
+
this.value = this.#swatch.value = this.textInput.value;
|
|
1192
|
+
this.setAttribute("value", this.value);
|
|
1193
|
+
}
|
|
1158
1194
|
handleAlphaInput(event) {
|
|
1159
1195
|
//do not propagate to onInput handler for web component
|
|
1160
1196
|
event.stopPropagation();
|
|
@@ -1215,7 +1251,16 @@ class FigInputColor extends HTMLElement {
|
|
|
1215
1251
|
}
|
|
1216
1252
|
|
|
1217
1253
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
1218
|
-
|
|
1254
|
+
switch (name) {
|
|
1255
|
+
case "value":
|
|
1256
|
+
if (this.textInput) {
|
|
1257
|
+
this.value = this.#swatch.value = this.textInput.value = newValue;
|
|
1258
|
+
} else {
|
|
1259
|
+
this.value = newValue;
|
|
1260
|
+
}
|
|
1261
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1219
1264
|
}
|
|
1220
1265
|
|
|
1221
1266
|
rgbAlphaToHex({ r, g, b }, a = 1) {
|
|
@@ -1458,14 +1503,16 @@ class FigComboInput extends HTMLElement {
|
|
|
1458
1503
|
</div>`;
|
|
1459
1504
|
requestAnimationFrame(() => {
|
|
1460
1505
|
this.input = this.querySelector("fig-input-text");
|
|
1461
|
-
this.
|
|
1506
|
+
this.dropdown = this.querySelector("fig-dropdown");
|
|
1462
1507
|
|
|
1463
|
-
this.
|
|
1508
|
+
this.dropdown.addEventListener(
|
|
1509
|
+
"input",
|
|
1510
|
+
this.handleSelectInput.bind(this)
|
|
1511
|
+
);
|
|
1464
1512
|
});
|
|
1465
1513
|
}
|
|
1466
1514
|
handleSelectInput(e) {
|
|
1467
|
-
this.value
|
|
1468
|
-
this.setAttribute("value", this.value);
|
|
1515
|
+
this.setAttribute("value", e.target.closest("fig-dropdown").value);
|
|
1469
1516
|
}
|
|
1470
1517
|
handleInput(e) {
|
|
1471
1518
|
this.value = this.input.value;
|