@rogieking/figui3 1.1.5 → 1.1.6
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/fig.js +65 -59
- package/package.json +1 -1
package/fig.js
CHANGED
|
@@ -1112,27 +1112,22 @@ window.customElements.define("fig-field", FigField);
|
|
|
1112
1112
|
|
|
1113
1113
|
/* Color swatch */
|
|
1114
1114
|
class FigInputColor extends HTMLElement {
|
|
1115
|
-
|
|
1115
|
+
rgba;
|
|
1116
|
+
hex;
|
|
1117
|
+
alpha;
|
|
1116
1118
|
#swatch;
|
|
1117
|
-
textInput;
|
|
1119
|
+
#textInput;
|
|
1118
1120
|
#alphaInput;
|
|
1119
1121
|
constructor() {
|
|
1120
1122
|
super();
|
|
1121
1123
|
}
|
|
1122
1124
|
connectedCallback() {
|
|
1123
|
-
this.#
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
{
|
|
1127
|
-
r: this.#rgba.r,
|
|
1128
|
-
g: this.#rgba.g,
|
|
1129
|
-
b: this.#rgba.b,
|
|
1130
|
-
},
|
|
1131
|
-
alpha
|
|
1132
|
-
);
|
|
1125
|
+
this.#syncHex(this.getAttribute("value"));
|
|
1126
|
+
this.value = this.hex;
|
|
1127
|
+
|
|
1133
1128
|
let html = ``;
|
|
1134
1129
|
if (this.getAttribute("text")) {
|
|
1135
|
-
let label = `<fig-input-text type="text" placeholder="Text" value="${this.
|
|
1130
|
+
let label = `<fig-input-text type="text" placeholder="Text" value="${this.hex}"></fig-input-text>`;
|
|
1136
1131
|
if (this.getAttribute("alpha") === "true") {
|
|
1137
1132
|
label += `<fig-tooltip text="Opacity">
|
|
1138
1133
|
<fig-input-text
|
|
@@ -1140,36 +1135,35 @@ class FigInputColor extends HTMLElement {
|
|
|
1140
1135
|
type="number"
|
|
1141
1136
|
min="0"
|
|
1142
1137
|
max="100"
|
|
1143
|
-
value="${alpha}">
|
|
1138
|
+
value="${this.alpha}">
|
|
1144
1139
|
<span slot="append">%</slot>
|
|
1145
1140
|
</fig-input-text>
|
|
1146
1141
|
</fig-tooltip>`;
|
|
1147
1142
|
}
|
|
1148
1143
|
html = `<div class="input-combo">
|
|
1149
|
-
<fig-chit type="color" disabled="false" value="${this.
|
|
1144
|
+
<fig-chit type="color" disabled="false" value="${this.hex}"></fig-chit>
|
|
1150
1145
|
${label}
|
|
1151
1146
|
</div>`;
|
|
1152
1147
|
} else {
|
|
1153
|
-
html = `<fig-chit type="color" disabled="false" value="${this.
|
|
1148
|
+
html = `<fig-chit type="color" disabled="false" value="${this.hex}"></fig-chit>`;
|
|
1154
1149
|
}
|
|
1155
1150
|
this.innerHTML = html;
|
|
1156
|
-
|
|
1157
|
-
this.style.setProperty("--alpha", this.#rgba.a);
|
|
1151
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1158
1152
|
|
|
1159
1153
|
requestAnimationFrame(() => {
|
|
1160
|
-
this.#swatch = this.querySelector("
|
|
1161
|
-
this
|
|
1154
|
+
this.#swatch = this.querySelector("fig-chit[type=color]");
|
|
1155
|
+
this.#textInput = this.querySelector("fig-input-text:not([type=number])");
|
|
1162
1156
|
this.#alphaInput = this.querySelector("fig-input-text[type=number]");
|
|
1163
1157
|
|
|
1164
1158
|
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
1165
1159
|
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
1166
1160
|
|
|
1167
|
-
if (this
|
|
1168
|
-
this
|
|
1169
|
-
this
|
|
1161
|
+
if (this.#textInput) {
|
|
1162
|
+
this.#textInput.value = this.#swatch.value = this.rgbAlphaToHex(
|
|
1163
|
+
this.rgba,
|
|
1170
1164
|
1
|
|
1171
1165
|
);
|
|
1172
|
-
this
|
|
1166
|
+
this.#textInput.addEventListener(
|
|
1173
1167
|
"input",
|
|
1174
1168
|
this.#handleTextInput.bind(this)
|
|
1175
1169
|
);
|
|
@@ -1183,26 +1177,47 @@ class FigInputColor extends HTMLElement {
|
|
|
1183
1177
|
}
|
|
1184
1178
|
});
|
|
1185
1179
|
}
|
|
1180
|
+
#syncHex(hexValue) {
|
|
1181
|
+
this.rgba = this.convertToRGBA(hexValue);
|
|
1182
|
+
this.hex = this.rgbAlphaToHex(
|
|
1183
|
+
{
|
|
1184
|
+
r: this.rgba.r,
|
|
1185
|
+
g: this.rgba.g,
|
|
1186
|
+
b: this.rgba.b,
|
|
1187
|
+
},
|
|
1188
|
+
1
|
|
1189
|
+
);
|
|
1190
|
+
this.alpha = (this.rgba.a * 100).toFixed(0);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1186
1193
|
#handleTextInput(event) {
|
|
1187
1194
|
//do not propagate to onInput handler for web component
|
|
1188
1195
|
event.stopPropagation();
|
|
1189
|
-
this
|
|
1190
|
-
this.
|
|
1196
|
+
this.#syncHex(event.target.value);
|
|
1197
|
+
this.value = this.hex;
|
|
1198
|
+
if (this.#alphaInput) {
|
|
1199
|
+
this.#alphaInput.setAttribute("value", this.alpha);
|
|
1200
|
+
}
|
|
1201
|
+
if (this.#swatch) {
|
|
1202
|
+
this.#swatch.setAttribute("value", this.hex);
|
|
1203
|
+
}
|
|
1204
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1191
1205
|
}
|
|
1206
|
+
|
|
1192
1207
|
handleAlphaInput(event) {
|
|
1193
1208
|
//do not propagate to onInput handler for web component
|
|
1194
1209
|
event.stopPropagation();
|
|
1195
|
-
this
|
|
1196
|
-
this
|
|
1210
|
+
this.rgba = this.convertToRGBA(this.#swatch.value);
|
|
1211
|
+
this.rgba.a = Number(this.#alphaInput.value) / 100;
|
|
1197
1212
|
this.value = this.rgbAlphaToHex(
|
|
1198
1213
|
{
|
|
1199
|
-
r: this
|
|
1200
|
-
g: this
|
|
1201
|
-
b: this
|
|
1214
|
+
r: this.rgba.r,
|
|
1215
|
+
g: this.rgba.g,
|
|
1216
|
+
b: this.rgba.b,
|
|
1202
1217
|
},
|
|
1203
|
-
|
|
1218
|
+
1
|
|
1204
1219
|
);
|
|
1205
|
-
this.style.setProperty("--alpha", this
|
|
1220
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1206
1221
|
const e = new CustomEvent("input", {
|
|
1207
1222
|
bubbles: true,
|
|
1208
1223
|
cancelable: true,
|
|
@@ -1217,25 +1232,12 @@ class FigInputColor extends HTMLElement {
|
|
|
1217
1232
|
handleInput(event) {
|
|
1218
1233
|
//do not propagate to onInput handler for web component
|
|
1219
1234
|
event.stopPropagation();
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
this.#rgba = this.convertToRGBA(this.#swatch.value);
|
|
1223
|
-
this.#rgba.a = alpha;
|
|
1224
|
-
if (this.textInput) {
|
|
1225
|
-
this.textInput.value = this.#swatch.value;
|
|
1226
|
-
}
|
|
1227
|
-
this.style.setProperty("--alpha", this.#rgba.a);
|
|
1228
|
-
this.value = this.rgbAlphaToHex(
|
|
1229
|
-
{
|
|
1230
|
-
r: this.#rgba.r,
|
|
1231
|
-
g: this.#rgba.g,
|
|
1232
|
-
b: this.#rgba.b,
|
|
1233
|
-
},
|
|
1234
|
-
alpha
|
|
1235
|
-
);
|
|
1235
|
+
let alpha = this.alpha;
|
|
1236
|
+
this.#syncHex(event.target.value);
|
|
1236
1237
|
this.alpha = alpha;
|
|
1237
|
-
|
|
1238
|
-
|
|
1238
|
+
this.value = this.hex;
|
|
1239
|
+
if (this.#textInput) {
|
|
1240
|
+
this.#textInput.setAttribute("value", this.value);
|
|
1239
1241
|
}
|
|
1240
1242
|
const e = new CustomEvent("input", {
|
|
1241
1243
|
bubbles: true,
|
|
@@ -1251,14 +1253,18 @@ class FigInputColor extends HTMLElement {
|
|
|
1251
1253
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
1252
1254
|
switch (name) {
|
|
1253
1255
|
case "value":
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
this.textInput.value =
|
|
1258
|
-
newValue.toUpperCase();
|
|
1259
|
-
} else {
|
|
1260
|
-
this.value = newValue.toUpperCase();
|
|
1256
|
+
this.#syncHex(newValue);
|
|
1257
|
+
if (this.#textInput) {
|
|
1258
|
+
this.#textInput.setAttribute("value", this.hex);
|
|
1261
1259
|
}
|
|
1260
|
+
if (this.#swatch) {
|
|
1261
|
+
this.#swatch.setAttribute("value", this.hex);
|
|
1262
|
+
}
|
|
1263
|
+
if (this.#alphaInput) {
|
|
1264
|
+
this.#alphaInput.setAttribute("value", this.alpha);
|
|
1265
|
+
}
|
|
1266
|
+
this.value = this.hex;
|
|
1267
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1262
1268
|
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1263
1269
|
break;
|
|
1264
1270
|
}
|
|
@@ -1549,7 +1555,7 @@ class FigChit extends HTMLElement {
|
|
|
1549
1555
|
connectedCallback() {
|
|
1550
1556
|
this.type = this.getAttribute("type") || "color";
|
|
1551
1557
|
this.src = this.getAttribute("src") || "";
|
|
1552
|
-
this.value = this.getAttribute("value") || "";
|
|
1558
|
+
this.value = this.getAttribute("value") || "#000000";
|
|
1553
1559
|
this.size = this.getAttribute("size") || "small";
|
|
1554
1560
|
this.disabled = this.getAttribute("disabled") === "true";
|
|
1555
1561
|
this.innerHTML = `<input type="color" value="${this.value}" />`;
|