@rogieking/figui3 1.1.4 → 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/README.md +2 -2
- package/example.html +5 -3
- package/fig.js +67 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ The library includes the following components:
|
|
|
36
36
|
## Installation
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
npm install
|
|
39
|
+
npm install @rogieking/figui3
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
```jsx
|
|
@@ -74,7 +74,7 @@ or
|
|
|
74
74
|
|
|
75
75
|
## Documentation
|
|
76
76
|
|
|
77
|
-
For detailed documentation and examples, visit our [documentation site](https://
|
|
77
|
+
For detailed documentation and examples, visit our [documentation site](https://github.com/rogie/figui3#readme).
|
|
78
78
|
|
|
79
79
|
## Browser Support
|
|
80
80
|
|
package/example.html
CHANGED
|
@@ -471,9 +471,11 @@
|
|
|
471
471
|
size="large"></fig-chit>
|
|
472
472
|
</hstack>
|
|
473
473
|
<br />
|
|
474
|
-
<
|
|
475
|
-
<
|
|
476
|
-
|
|
474
|
+
<p>Some paragraph text here with a
|
|
475
|
+
<fig-tooltip text="Tooltip text">
|
|
476
|
+
<em>Tooltip</em>
|
|
477
|
+
</fig-tooltip> for more information.
|
|
478
|
+
</p>
|
|
477
479
|
<br /><br />
|
|
478
480
|
<hstack>
|
|
479
481
|
<input type="radio"
|
package/fig.js
CHANGED
|
@@ -1112,29 +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.
|
|
1136
|
-
"value"
|
|
1137
|
-
)}"></fig-input-text>`;
|
|
1130
|
+
let label = `<fig-input-text type="text" placeholder="Text" value="${this.hex}"></fig-input-text>`;
|
|
1138
1131
|
if (this.getAttribute("alpha") === "true") {
|
|
1139
1132
|
label += `<fig-tooltip text="Opacity">
|
|
1140
1133
|
<fig-input-text
|
|
@@ -1142,36 +1135,35 @@ class FigInputColor extends HTMLElement {
|
|
|
1142
1135
|
type="number"
|
|
1143
1136
|
min="0"
|
|
1144
1137
|
max="100"
|
|
1145
|
-
value="${alpha}">
|
|
1138
|
+
value="${this.alpha}">
|
|
1146
1139
|
<span slot="append">%</slot>
|
|
1147
1140
|
</fig-input-text>
|
|
1148
1141
|
</fig-tooltip>`;
|
|
1149
1142
|
}
|
|
1150
1143
|
html = `<div class="input-combo">
|
|
1151
|
-
<fig-chit type="color" disabled="false" value="${this.
|
|
1144
|
+
<fig-chit type="color" disabled="false" value="${this.hex}"></fig-chit>
|
|
1152
1145
|
${label}
|
|
1153
1146
|
</div>`;
|
|
1154
1147
|
} else {
|
|
1155
|
-
html = `<fig-chit type="color" disabled="false" value="${this.
|
|
1148
|
+
html = `<fig-chit type="color" disabled="false" value="${this.hex}"></fig-chit>`;
|
|
1156
1149
|
}
|
|
1157
1150
|
this.innerHTML = html;
|
|
1158
|
-
|
|
1159
|
-
this.style.setProperty("--alpha", this.#rgba.a);
|
|
1151
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1160
1152
|
|
|
1161
1153
|
requestAnimationFrame(() => {
|
|
1162
|
-
this.#swatch = this.querySelector("
|
|
1163
|
-
this
|
|
1154
|
+
this.#swatch = this.querySelector("fig-chit[type=color]");
|
|
1155
|
+
this.#textInput = this.querySelector("fig-input-text:not([type=number])");
|
|
1164
1156
|
this.#alphaInput = this.querySelector("fig-input-text[type=number]");
|
|
1165
1157
|
|
|
1166
1158
|
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
1167
1159
|
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
1168
1160
|
|
|
1169
|
-
if (this
|
|
1170
|
-
this
|
|
1171
|
-
this
|
|
1161
|
+
if (this.#textInput) {
|
|
1162
|
+
this.#textInput.value = this.#swatch.value = this.rgbAlphaToHex(
|
|
1163
|
+
this.rgba,
|
|
1172
1164
|
1
|
|
1173
1165
|
);
|
|
1174
|
-
this
|
|
1166
|
+
this.#textInput.addEventListener(
|
|
1175
1167
|
"input",
|
|
1176
1168
|
this.#handleTextInput.bind(this)
|
|
1177
1169
|
);
|
|
@@ -1185,26 +1177,47 @@ class FigInputColor extends HTMLElement {
|
|
|
1185
1177
|
}
|
|
1186
1178
|
});
|
|
1187
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
|
+
|
|
1188
1193
|
#handleTextInput(event) {
|
|
1189
1194
|
//do not propagate to onInput handler for web component
|
|
1190
1195
|
event.stopPropagation();
|
|
1191
|
-
this
|
|
1192
|
-
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);
|
|
1193
1205
|
}
|
|
1206
|
+
|
|
1194
1207
|
handleAlphaInput(event) {
|
|
1195
1208
|
//do not propagate to onInput handler for web component
|
|
1196
1209
|
event.stopPropagation();
|
|
1197
|
-
this
|
|
1198
|
-
this
|
|
1210
|
+
this.rgba = this.convertToRGBA(this.#swatch.value);
|
|
1211
|
+
this.rgba.a = Number(this.#alphaInput.value) / 100;
|
|
1199
1212
|
this.value = this.rgbAlphaToHex(
|
|
1200
1213
|
{
|
|
1201
|
-
r: this
|
|
1202
|
-
g: this
|
|
1203
|
-
b: this
|
|
1214
|
+
r: this.rgba.r,
|
|
1215
|
+
g: this.rgba.g,
|
|
1216
|
+
b: this.rgba.b,
|
|
1204
1217
|
},
|
|
1205
|
-
|
|
1218
|
+
1
|
|
1206
1219
|
);
|
|
1207
|
-
this.style.setProperty("--alpha", this
|
|
1220
|
+
this.style.setProperty("--alpha", this.rgba.a);
|
|
1208
1221
|
const e = new CustomEvent("input", {
|
|
1209
1222
|
bubbles: true,
|
|
1210
1223
|
cancelable: true,
|
|
@@ -1219,25 +1232,12 @@ class FigInputColor extends HTMLElement {
|
|
|
1219
1232
|
handleInput(event) {
|
|
1220
1233
|
//do not propagate to onInput handler for web component
|
|
1221
1234
|
event.stopPropagation();
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
this.#rgba = this.convertToRGBA(this.#swatch.value);
|
|
1225
|
-
this.#rgba.a = alpha;
|
|
1226
|
-
if (this.textInput) {
|
|
1227
|
-
this.textInput.value = this.#swatch.value;
|
|
1228
|
-
}
|
|
1229
|
-
this.style.setProperty("--alpha", this.#rgba.a);
|
|
1230
|
-
this.value = this.rgbAlphaToHex(
|
|
1231
|
-
{
|
|
1232
|
-
r: this.#rgba.r,
|
|
1233
|
-
g: this.#rgba.g,
|
|
1234
|
-
b: this.#rgba.b,
|
|
1235
|
-
},
|
|
1236
|
-
alpha
|
|
1237
|
-
);
|
|
1235
|
+
let alpha = this.alpha;
|
|
1236
|
+
this.#syncHex(event.target.value);
|
|
1238
1237
|
this.alpha = alpha;
|
|
1239
|
-
|
|
1240
|
-
|
|
1238
|
+
this.value = this.hex;
|
|
1239
|
+
if (this.#textInput) {
|
|
1240
|
+
this.#textInput.setAttribute("value", this.value);
|
|
1241
1241
|
}
|
|
1242
1242
|
const e = new CustomEvent("input", {
|
|
1243
1243
|
bubbles: true,
|
|
@@ -1253,11 +1253,18 @@ class FigInputColor extends HTMLElement {
|
|
|
1253
1253
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
1254
1254
|
switch (name) {
|
|
1255
1255
|
case "value":
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
this.value = newValue;
|
|
1256
|
+
this.#syncHex(newValue);
|
|
1257
|
+
if (this.#textInput) {
|
|
1258
|
+
this.#textInput.setAttribute("value", this.hex);
|
|
1260
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);
|
|
1261
1268
|
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
1262
1269
|
break;
|
|
1263
1270
|
}
|
|
@@ -1279,13 +1286,13 @@ class FigInputColor extends HTMLElement {
|
|
|
1279
1286
|
|
|
1280
1287
|
// If alpha is 1, return 6-digit hex
|
|
1281
1288
|
if (a === 1) {
|
|
1282
|
-
return `#${hexR}${hexG}${hexB}
|
|
1289
|
+
return `#${hexR}${hexG}${hexB}`.toUpperCase();
|
|
1283
1290
|
}
|
|
1284
1291
|
|
|
1285
1292
|
// Otherwise, include alpha in 8-digit hex
|
|
1286
1293
|
const alpha = Math.round(a * 255);
|
|
1287
1294
|
const hexA = alpha.toString(16).padStart(2, "0");
|
|
1288
|
-
return `#${hexR}${hexG}${hexB}${hexA}
|
|
1295
|
+
return `#${hexR}${hexG}${hexB}${hexA}`.toUpperCase();
|
|
1289
1296
|
}
|
|
1290
1297
|
|
|
1291
1298
|
convertToRGBA(color) {
|
|
@@ -1548,7 +1555,7 @@ class FigChit extends HTMLElement {
|
|
|
1548
1555
|
connectedCallback() {
|
|
1549
1556
|
this.type = this.getAttribute("type") || "color";
|
|
1550
1557
|
this.src = this.getAttribute("src") || "";
|
|
1551
|
-
this.value = this.getAttribute("value") || "";
|
|
1558
|
+
this.value = this.getAttribute("value") || "#000000";
|
|
1552
1559
|
this.size = this.getAttribute("size") || "small";
|
|
1553
1560
|
this.disabled = this.getAttribute("disabled") === "true";
|
|
1554
1561
|
this.innerHTML = `<input type="color" value="${this.value}" />`;
|