@rogieking/figui3 1.0.99 → 1.1.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/example.html +3 -1
- package/fig.js +60 -18
- 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>
|
|
@@ -424,6 +424,8 @@
|
|
|
424
424
|
</fig-combo-input>
|
|
425
425
|
<br /><br />
|
|
426
426
|
<fig-input-text type="number"
|
|
427
|
+
min="0"
|
|
428
|
+
max="360"
|
|
427
429
|
value="90">
|
|
428
430
|
<span slot="append">°</span>
|
|
429
431
|
</fig-input-text>
|
package/fig.js
CHANGED
|
@@ -927,21 +927,16 @@ class FigInputText extends HTMLElement {
|
|
|
927
927
|
#handleInput(e) {
|
|
928
928
|
let value = e.target.value;
|
|
929
929
|
if (this.type === "number") {
|
|
930
|
-
|
|
931
|
-
value = Math.min(this.min, value);
|
|
932
|
-
}
|
|
933
|
-
if (this.max) {
|
|
934
|
-
value = Math.max(this.max, value);
|
|
935
|
-
}
|
|
930
|
+
value = this.#sanitizeInput(value);
|
|
936
931
|
value = value / (this.transform || 1);
|
|
937
932
|
}
|
|
938
|
-
this.value
|
|
933
|
+
this.setAttribute("value", value);
|
|
939
934
|
}
|
|
940
935
|
#handleMouseMove(e) {
|
|
941
936
|
if (e.altKey) {
|
|
942
937
|
const step = (this.step || 1) * e.movementX;
|
|
943
|
-
const value = Number(this.
|
|
944
|
-
this.setAttribute("value", value
|
|
938
|
+
const value = this.#sanitizeInput(Number(this.value) + step).toFixed(2);
|
|
939
|
+
this.setAttribute("value", value);
|
|
945
940
|
}
|
|
946
941
|
}
|
|
947
942
|
#handleMouseDown(e) {
|
|
@@ -950,6 +945,7 @@ class FigInputText extends HTMLElement {
|
|
|
950
945
|
this.style.cursor =
|
|
951
946
|
document.body.style.cursor =
|
|
952
947
|
"ew-resize";
|
|
948
|
+
this.style.userSelect = "none";
|
|
953
949
|
// Use the pre-bound handlers
|
|
954
950
|
window.addEventListener("pointermove", this.#boundMouseMove);
|
|
955
951
|
window.addEventListener("pointerup", this.#boundMouseUp);
|
|
@@ -960,10 +956,24 @@ class FigInputText extends HTMLElement {
|
|
|
960
956
|
this.style.cursor =
|
|
961
957
|
document.body.style.cursor =
|
|
962
958
|
"";
|
|
959
|
+
this.style.userSelect = "all";
|
|
963
960
|
// Remove the pre-bound handlers
|
|
964
961
|
window.removeEventListener("pointermove", this.#boundMouseMove);
|
|
965
962
|
window.removeEventListener("pointerup", this.#boundMouseUp);
|
|
966
963
|
}
|
|
964
|
+
#sanitizeInput(value) {
|
|
965
|
+
let sanitized = value;
|
|
966
|
+
if (this.type === "number") {
|
|
967
|
+
sanitized = Number(sanitized);
|
|
968
|
+
if (typeof this.min === "number") {
|
|
969
|
+
sanitized = Math.max(this.min, sanitized);
|
|
970
|
+
}
|
|
971
|
+
if (typeof this.max === "number") {
|
|
972
|
+
sanitized = Math.min(this.max, sanitized);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return sanitized;
|
|
976
|
+
}
|
|
967
977
|
|
|
968
978
|
static get observedAttributes() {
|
|
969
979
|
return [
|
|
@@ -983,7 +993,9 @@ class FigInputText extends HTMLElement {
|
|
|
983
993
|
if (this.input) {
|
|
984
994
|
switch (name) {
|
|
985
995
|
case "disabled":
|
|
986
|
-
this.disabled = this.input.disabled =
|
|
996
|
+
this.disabled = this.input.disabled =
|
|
997
|
+
newValue === "true" ||
|
|
998
|
+
(newValue === undefined && newValue !== null);
|
|
987
999
|
break;
|
|
988
1000
|
case "transform":
|
|
989
1001
|
if (this.type === "number") {
|
|
@@ -994,16 +1006,27 @@ class FigInputText extends HTMLElement {
|
|
|
994
1006
|
this.value = this.#transformNumber(this.value);
|
|
995
1007
|
}
|
|
996
1008
|
break;
|
|
997
|
-
|
|
1009
|
+
case "value":
|
|
998
1010
|
let value = newValue;
|
|
999
1011
|
if (this.type === "number") {
|
|
1000
|
-
|
|
1012
|
+
let sanitized = this.#sanitizeInput(value);
|
|
1013
|
+
this.value = sanitized;
|
|
1014
|
+
this.input.value = this.#transformNumber(sanitized);
|
|
1001
1015
|
}
|
|
1002
|
-
this
|
|
1016
|
+
this.value = value;
|
|
1017
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1018
|
+
break;
|
|
1019
|
+
case "min":
|
|
1020
|
+
case "max":
|
|
1021
|
+
case "step":
|
|
1022
|
+
this[name] = this.input[name] = Number(newValue);
|
|
1003
1023
|
if (this.input) {
|
|
1004
|
-
this.input.setAttribute(name,
|
|
1024
|
+
this.input.setAttribute(name, newValue);
|
|
1005
1025
|
}
|
|
1006
1026
|
break;
|
|
1027
|
+
default:
|
|
1028
|
+
this[name] = this.input[name] = value;
|
|
1029
|
+
break;
|
|
1007
1030
|
}
|
|
1008
1031
|
}
|
|
1009
1032
|
}
|
|
@@ -1106,7 +1129,7 @@ class FigInputColor extends HTMLElement {
|
|
|
1106
1129
|
);
|
|
1107
1130
|
let html = ``;
|
|
1108
1131
|
if (this.getAttribute("text")) {
|
|
1109
|
-
let label = `<fig-input-text placeholder="Text" value="${this.getAttribute(
|
|
1132
|
+
let label = `<fig-input-text type="text" placeholder="Text" value="${this.getAttribute(
|
|
1110
1133
|
"value"
|
|
1111
1134
|
)}"></fig-input-text>`;
|
|
1112
1135
|
if (this.getAttribute("alpha") === "true") {
|
|
@@ -1134,8 +1157,8 @@ class FigInputColor extends HTMLElement {
|
|
|
1134
1157
|
|
|
1135
1158
|
requestAnimationFrame(() => {
|
|
1136
1159
|
this.#swatch = this.querySelector("input[type=color]");
|
|
1137
|
-
this.textInput = this.querySelector("input[type=
|
|
1138
|
-
this.#alphaInput = this.querySelector("input[type=number]");
|
|
1160
|
+
this.textInput = this.querySelector("fig-input-text:not([type=number])");
|
|
1161
|
+
this.#alphaInput = this.querySelector("fig-input-text[type=number]");
|
|
1139
1162
|
|
|
1140
1163
|
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
1141
1164
|
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
@@ -1145,6 +1168,10 @@ class FigInputColor extends HTMLElement {
|
|
|
1145
1168
|
this.#rgba,
|
|
1146
1169
|
1
|
|
1147
1170
|
);
|
|
1171
|
+
this.textInput.addEventListener(
|
|
1172
|
+
"input",
|
|
1173
|
+
this.#handleTextInput.bind(this)
|
|
1174
|
+
);
|
|
1148
1175
|
}
|
|
1149
1176
|
|
|
1150
1177
|
if (this.#alphaInput) {
|
|
@@ -1155,6 +1182,12 @@ class FigInputColor extends HTMLElement {
|
|
|
1155
1182
|
}
|
|
1156
1183
|
});
|
|
1157
1184
|
}
|
|
1185
|
+
#handleTextInput(event) {
|
|
1186
|
+
//do not propagate to onInput handler for web component
|
|
1187
|
+
event.stopPropagation();
|
|
1188
|
+
this.value = this.#swatch.value = this.textInput.value;
|
|
1189
|
+
this.setAttribute("value", this.value);
|
|
1190
|
+
}
|
|
1158
1191
|
handleAlphaInput(event) {
|
|
1159
1192
|
//do not propagate to onInput handler for web component
|
|
1160
1193
|
event.stopPropagation();
|
|
@@ -1215,7 +1248,16 @@ class FigInputColor extends HTMLElement {
|
|
|
1215
1248
|
}
|
|
1216
1249
|
|
|
1217
1250
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
1218
|
-
|
|
1251
|
+
switch (name) {
|
|
1252
|
+
case "value":
|
|
1253
|
+
if (this.textInput) {
|
|
1254
|
+
this.value = this.#swatch.value = this.textInput.value = newValue;
|
|
1255
|
+
} else {
|
|
1256
|
+
this.value = newValue;
|
|
1257
|
+
}
|
|
1258
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1219
1261
|
}
|
|
1220
1262
|
|
|
1221
1263
|
rgbAlphaToHex({ r, g, b }, a = 1) {
|