@rogieking/figui3 1.0.81 → 1.0.83
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 +26 -1
- package/fig.js +108 -52
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -19,6 +19,27 @@
|
|
|
19
19
|
<h2>Heading 2</h2>
|
|
20
20
|
<h3>Heading 3</h3>
|
|
21
21
|
<br />
|
|
22
|
+
|
|
23
|
+
<fig-slider min="0"
|
|
24
|
+
max="1"
|
|
25
|
+
transform="100"
|
|
26
|
+
step="0.01"
|
|
27
|
+
text="true"
|
|
28
|
+
style="width:300px;"
|
|
29
|
+
value="0.5">
|
|
30
|
+
</fig-slider>
|
|
31
|
+
<br />
|
|
32
|
+
<fig-input-text min="0"
|
|
33
|
+
max="1"
|
|
34
|
+
step="0.1"
|
|
35
|
+
transform="100"
|
|
36
|
+
type="number"
|
|
37
|
+
style="width: 100px;"
|
|
38
|
+
value="0.5"
|
|
39
|
+
text="true">
|
|
40
|
+
<span slot="append">%</span>
|
|
41
|
+
</fig-input-text>
|
|
42
|
+
<br />
|
|
22
43
|
<details>
|
|
23
44
|
<summary>Details</summary>
|
|
24
45
|
<p>Some more content here</p>
|
|
@@ -28,7 +49,11 @@
|
|
|
28
49
|
<label>Opacity</label>
|
|
29
50
|
<fig-slider type="opacity"
|
|
30
51
|
full
|
|
31
|
-
value="0.
|
|
52
|
+
value="0.5"
|
|
53
|
+
min="0"
|
|
54
|
+
max="1"
|
|
55
|
+
step="0.01"
|
|
56
|
+
transform="100"
|
|
32
57
|
color="#ff0000"
|
|
33
58
|
units="%"
|
|
34
59
|
text="true"></fig-slider>
|
package/fig.js
CHANGED
|
@@ -636,16 +636,24 @@ class FigSlider extends HTMLElement {
|
|
|
636
636
|
hue: { min: 0, max: 255, step: 1 },
|
|
637
637
|
delta: { min: -100, max: 100, step: 1 },
|
|
638
638
|
stepper: { min: 0, max: 100, step: 25 },
|
|
639
|
-
opacity: { min: 0, max: 100, step: 0.
|
|
639
|
+
opacity: { min: 0, max: 100, step: 0.1, color: "#FF0000" },
|
|
640
640
|
};
|
|
641
641
|
constructor() {
|
|
642
642
|
super();
|
|
643
643
|
}
|
|
644
644
|
#regenerateInnerHTML() {
|
|
645
|
+
this.value = Number(this.getAttribute("value") || 0);
|
|
646
|
+
this.default = this.getAttribute("default") || null;
|
|
647
|
+
this.type = this.getAttribute("type") || "range";
|
|
648
|
+
this.text = this.getAttribute("text") || false;
|
|
649
|
+
this.units = this.getAttribute("units") || "";
|
|
650
|
+
this.transform = Number(this.getAttribute("transform") || 1);
|
|
651
|
+
this.disabled = this.getAttribute("disabled") ? true : false;
|
|
652
|
+
|
|
645
653
|
const defaults = this.#typeDefaults[this.type];
|
|
646
|
-
this.min = this.getAttribute("min") || defaults.min;
|
|
647
|
-
this.max = this.getAttribute("max") || defaults.max;
|
|
648
|
-
this.step = this.getAttribute("step") || defaults.step;
|
|
654
|
+
this.min = Number(this.getAttribute("min") || defaults.min);
|
|
655
|
+
this.max = Number(this.getAttribute("max") || defaults.max);
|
|
656
|
+
this.step = Number(this.getAttribute("step") || defaults.step);
|
|
649
657
|
this.color = this.getAttribute("color") || defaults?.color;
|
|
650
658
|
|
|
651
659
|
if (this.color) {
|
|
@@ -671,6 +679,7 @@ class FigSlider extends HTMLElement {
|
|
|
671
679
|
type="number"
|
|
672
680
|
min="${this.min}"
|
|
673
681
|
max="${this.max}"
|
|
682
|
+
transform="${this.transform}"
|
|
674
683
|
step="${this.step}"
|
|
675
684
|
value="${this.value}">
|
|
676
685
|
${
|
|
@@ -683,18 +692,18 @@ class FigSlider extends HTMLElement {
|
|
|
683
692
|
html = slider;
|
|
684
693
|
}
|
|
685
694
|
this.innerHTML = html;
|
|
686
|
-
|
|
687
|
-
}
|
|
688
|
-
#setupBindings() {
|
|
695
|
+
|
|
689
696
|
//child nodes hack
|
|
690
697
|
requestAnimationFrame(() => {
|
|
691
698
|
this.input = this.querySelector("[type=range]");
|
|
692
699
|
this.input.removeEventListener("input", this.handleInput);
|
|
693
700
|
this.input.addEventListener("input", this.handleInput.bind(this));
|
|
694
|
-
this.handleInput();
|
|
695
701
|
|
|
696
702
|
if (this.default) {
|
|
697
|
-
this.style.setProperty(
|
|
703
|
+
this.style.setProperty(
|
|
704
|
+
"--default",
|
|
705
|
+
this.#calculateNormal(this.default)
|
|
706
|
+
);
|
|
698
707
|
}
|
|
699
708
|
|
|
700
709
|
this.datalist = this.querySelector("datalist");
|
|
@@ -713,19 +722,14 @@ class FigSlider extends HTMLElement {
|
|
|
713
722
|
this.handleTextInput.bind(this)
|
|
714
723
|
);
|
|
715
724
|
}
|
|
725
|
+
|
|
726
|
+
this.handleInput();
|
|
716
727
|
});
|
|
717
728
|
}
|
|
729
|
+
|
|
718
730
|
connectedCallback() {
|
|
719
|
-
this.value = this.getAttribute("value");
|
|
720
|
-
this.default = this.getAttribute("default") || null;
|
|
721
|
-
this.type = this.getAttribute("type") || "range";
|
|
722
|
-
this.text = this.getAttribute("text") || false;
|
|
723
|
-
this.units = this.getAttribute("units") || "";
|
|
724
|
-
this.disabled = this.getAttribute("disabled") ? true : false;
|
|
725
731
|
this.initialInnerHTML = this.innerHTML;
|
|
726
|
-
|
|
727
732
|
this.#regenerateInnerHTML();
|
|
728
|
-
this.#setupBindings();
|
|
729
733
|
}
|
|
730
734
|
static get observedAttributes() {
|
|
731
735
|
return [
|
|
@@ -737,6 +741,7 @@ class FigSlider extends HTMLElement {
|
|
|
737
741
|
"disabled",
|
|
738
742
|
"color",
|
|
739
743
|
"units",
|
|
744
|
+
"transform",
|
|
740
745
|
];
|
|
741
746
|
}
|
|
742
747
|
|
|
@@ -760,22 +765,26 @@ class FigSlider extends HTMLElement {
|
|
|
760
765
|
this.figInputText.setAttribute("disabled", this.disabled);
|
|
761
766
|
}
|
|
762
767
|
break;
|
|
763
|
-
case "
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
+
case "value":
|
|
769
|
+
this.value = newValue;
|
|
770
|
+
if (this.figInputText) {
|
|
771
|
+
this.figInputText.setAttribute("value", newValue);
|
|
772
|
+
}
|
|
773
|
+
break;
|
|
774
|
+
case "transform":
|
|
775
|
+
this.transform = Number(newValue) || 1;
|
|
768
776
|
if (this.figInputText) {
|
|
769
|
-
this.figInputText
|
|
770
|
-
this.figInputText.setAttribute(name, newValue);
|
|
777
|
+
this.figInputText.setAttribute("transform", this.transform);
|
|
771
778
|
}
|
|
772
779
|
break;
|
|
780
|
+
case "min":
|
|
781
|
+
case "max":
|
|
782
|
+
case "step":
|
|
773
783
|
case "type":
|
|
774
784
|
case "text":
|
|
775
785
|
case "units":
|
|
776
786
|
this[name] = newValue;
|
|
777
787
|
this.#regenerateInnerHTML();
|
|
778
|
-
this.#setupBindings();
|
|
779
788
|
break;
|
|
780
789
|
default:
|
|
781
790
|
this[name] = this.input[name] = newValue;
|
|
@@ -790,7 +799,7 @@ class FigSlider extends HTMLElement {
|
|
|
790
799
|
this.handleInput();
|
|
791
800
|
}
|
|
792
801
|
}
|
|
793
|
-
calculateNormal(value) {
|
|
802
|
+
#calculateNormal(value) {
|
|
794
803
|
let min = Number(this.input.min);
|
|
795
804
|
let max = Number(this.input.max);
|
|
796
805
|
let val = Number(value);
|
|
@@ -800,8 +809,8 @@ class FigSlider extends HTMLElement {
|
|
|
800
809
|
handleInput() {
|
|
801
810
|
let val = Number(this.input.value);
|
|
802
811
|
this.value = val;
|
|
803
|
-
let complete = this
|
|
804
|
-
let defaultValue = this
|
|
812
|
+
let complete = this.#calculateNormal(val);
|
|
813
|
+
let defaultValue = this.#calculateNormal(this.default);
|
|
805
814
|
this.style.setProperty("--slider-complete", complete);
|
|
806
815
|
this.style.setProperty("--default", defaultValue);
|
|
807
816
|
this.style.setProperty("--unchanged", complete === defaultValue ? 1 : 0);
|
|
@@ -820,12 +829,28 @@ class FigInputText extends HTMLElement {
|
|
|
820
829
|
this.multiline = this.hasAttribute("multiline") || false;
|
|
821
830
|
this.value = this.getAttribute("value") || "";
|
|
822
831
|
this.type = this.getAttribute("type") || "text";
|
|
832
|
+
if (this.type === "number") {
|
|
833
|
+
if (this.getAttribute("step")) {
|
|
834
|
+
this.step = Number(this.getAttribute("step"));
|
|
835
|
+
}
|
|
836
|
+
if (this.getAttribute("min")) {
|
|
837
|
+
this.min = Number(this.getAttribute("min"));
|
|
838
|
+
}
|
|
839
|
+
if (this.getAttribute("max")) {
|
|
840
|
+
this.max = Number(this.getAttribute("max"));
|
|
841
|
+
}
|
|
842
|
+
this.transform = Number(this.getAttribute("transform") || 1);
|
|
843
|
+
if (this.getAttribute("value")) {
|
|
844
|
+
this.value = Number(this.value);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
823
847
|
this.placeholder = this.getAttribute("placeholder") || "";
|
|
824
|
-
|
|
825
848
|
let html = `<input
|
|
826
849
|
type="${this.type}"
|
|
827
850
|
placeholder="${this.placeholder}"
|
|
828
|
-
value="${
|
|
851
|
+
value="${
|
|
852
|
+
this.type === "number" ? this.#transformNumber(this.value) : this.value
|
|
853
|
+
}" />`;
|
|
829
854
|
if (this.multiline) {
|
|
830
855
|
html = `<textarea
|
|
831
856
|
placeholder="${this.placeholder}">${this.value}</textarea>`;
|
|
@@ -849,23 +874,33 @@ class FigInputText extends HTMLElement {
|
|
|
849
874
|
|
|
850
875
|
this.input = this.querySelector("input,textarea");
|
|
851
876
|
|
|
852
|
-
if (this.
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
877
|
+
if (this.type === "number") {
|
|
878
|
+
if (this.getAttribute("min")) {
|
|
879
|
+
this.input.setAttribute("min", this.#transformNumber(this.min));
|
|
880
|
+
}
|
|
881
|
+
if (this.getAttribute("max")) {
|
|
882
|
+
this.input.setAttribute("max", this.#transformNumber(this.max));
|
|
883
|
+
}
|
|
884
|
+
if (this.getAttribute("step")) {
|
|
885
|
+
this.input.setAttribute("step", this.#transformNumber(this.step));
|
|
886
|
+
}
|
|
860
887
|
}
|
|
861
|
-
this.input.addEventListener("input", this
|
|
888
|
+
this.input.addEventListener("input", this.#handleInput.bind(this));
|
|
862
889
|
});
|
|
863
890
|
}
|
|
864
891
|
focus() {
|
|
865
892
|
this.input.focus();
|
|
866
893
|
}
|
|
867
|
-
|
|
868
|
-
|
|
894
|
+
#transformNumber(value) {
|
|
895
|
+
return Number(value) * (this.transform || 1);
|
|
896
|
+
}
|
|
897
|
+
#handleInput(e) {
|
|
898
|
+
let value = Number(e.target.value);
|
|
899
|
+
if (this.type === "number") {
|
|
900
|
+
this.value = value / (this.transform || 1);
|
|
901
|
+
} else {
|
|
902
|
+
this.value = value;
|
|
903
|
+
}
|
|
869
904
|
}
|
|
870
905
|
|
|
871
906
|
static get observedAttributes() {
|
|
@@ -878,6 +913,7 @@ class FigInputText extends HTMLElement {
|
|
|
878
913
|
"step",
|
|
879
914
|
"min",
|
|
880
915
|
"max",
|
|
916
|
+
"transform",
|
|
881
917
|
];
|
|
882
918
|
}
|
|
883
919
|
|
|
@@ -887,10 +923,23 @@ class FigInputText extends HTMLElement {
|
|
|
887
923
|
case "disabled":
|
|
888
924
|
this.disabled = this.input.disabled = newValue;
|
|
889
925
|
break;
|
|
926
|
+
case "transform":
|
|
927
|
+
if (this.type === "number") {
|
|
928
|
+
this.transform = Number(newValue) || 1;
|
|
929
|
+
this.min = this.#transformNumber(this.min);
|
|
930
|
+
this.max = this.#transformNumber(this.max);
|
|
931
|
+
this.step = this.#transformNumber(this.step);
|
|
932
|
+
this.value = this.#transformNumber(this.value);
|
|
933
|
+
}
|
|
934
|
+
break;
|
|
890
935
|
default:
|
|
891
|
-
|
|
936
|
+
let value = newValue;
|
|
937
|
+
if (this.type === "number") {
|
|
938
|
+
value = this.#transformNumber(value);
|
|
939
|
+
}
|
|
940
|
+
this[name] = this.input[name] = value;
|
|
892
941
|
if (this.input) {
|
|
893
|
-
this.input.setAttribute(name,
|
|
942
|
+
this.input.setAttribute(name, value);
|
|
894
943
|
}
|
|
895
944
|
break;
|
|
896
945
|
}
|
|
@@ -1393,15 +1442,14 @@ class FigChit extends HTMLElement {
|
|
|
1393
1442
|
this.value = this.getAttribute("value") || "";
|
|
1394
1443
|
this.size = this.getAttribute("size") || "small";
|
|
1395
1444
|
this.disabled = this.getAttribute("disabled") === "true" ? true : false;
|
|
1396
|
-
this.variant = this.getAttribute("variant") || "square";
|
|
1397
1445
|
this.innerHTML = `<input type="color" value="${this.value}" />`;
|
|
1446
|
+
this.#updateSrc(this.src);
|
|
1398
1447
|
|
|
1399
1448
|
requestAnimationFrame(() => {
|
|
1400
1449
|
this.input = this.querySelector("input");
|
|
1401
|
-
this.updateSrc(this.src);
|
|
1402
1450
|
});
|
|
1403
1451
|
}
|
|
1404
|
-
updateSrc(src) {
|
|
1452
|
+
#updateSrc(src) {
|
|
1405
1453
|
if (src) {
|
|
1406
1454
|
this.src = src;
|
|
1407
1455
|
this.style.setProperty("--src", `url(${src})`);
|
|
@@ -1410,14 +1458,22 @@ class FigChit extends HTMLElement {
|
|
|
1410
1458
|
}
|
|
1411
1459
|
}
|
|
1412
1460
|
static get observedAttributes() {
|
|
1413
|
-
return ["
|
|
1461
|
+
return ["src", "value", "disabled"];
|
|
1414
1462
|
}
|
|
1415
1463
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1464
|
+
switch (name) {
|
|
1465
|
+
case "src":
|
|
1466
|
+
this.#updateSrc(newValue);
|
|
1467
|
+
break;
|
|
1468
|
+
case "disabled":
|
|
1469
|
+
this.disabled = newValue.toLowerCase() === "true";
|
|
1470
|
+
break;
|
|
1471
|
+
default:
|
|
1472
|
+
if (this.input) {
|
|
1473
|
+
this.input[name] = newValue;
|
|
1474
|
+
}
|
|
1475
|
+
this.#updateSrc(this.src);
|
|
1476
|
+
break;
|
|
1421
1477
|
}
|
|
1422
1478
|
}
|
|
1423
1479
|
}
|
package/package.json
CHANGED