@rogieking/figui3 1.0.82 → 1.0.84

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.
Files changed (3) hide show
  1. package/example.html +25 -8
  2. package/fig.js +85 -30
  3. package/package.json +1 -1
package/example.html CHANGED
@@ -19,13 +19,26 @@
19
19
  <h2>Heading 2</h2>
20
20
  <h3>Heading 3</h3>
21
21
  <br />
22
- <fig-slider id="test"
23
- type="range"
24
- min="0"
25
- max="256"
26
- value="100"
27
- units="px"
28
- text="true"></fig-slider>
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>
29
42
  <br />
30
43
  <details>
31
44
  <summary>Details</summary>
@@ -36,7 +49,11 @@
36
49
  <label>Opacity</label>
37
50
  <fig-slider type="opacity"
38
51
  full
39
- value="0.75"
52
+ value="0.5"
53
+ min="0"
54
+ max="1"
55
+ step="0.01"
56
+ transform="100"
40
57
  color="#ff0000"
41
58
  units="%"
42
59
  text="true"></fig-slider>
package/fig.js CHANGED
@@ -636,23 +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.01, color: "#FF0000" },
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 = this.getAttribute("value") || 0;
645
+ this.value = Number(this.getAttribute("value") || 0);
646
646
  this.default = this.getAttribute("default") || null;
647
647
  this.type = this.getAttribute("type") || "range";
648
648
  this.text = this.getAttribute("text") || false;
649
649
  this.units = this.getAttribute("units") || "";
650
+ this.transform = Number(this.getAttribute("transform") || 1);
650
651
  this.disabled = this.getAttribute("disabled") ? true : false;
651
652
 
652
653
  const defaults = this.#typeDefaults[this.type];
653
- this.min = this.getAttribute("min") || defaults.min;
654
- this.max = this.getAttribute("max") || defaults.max;
655
- 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);
656
657
  this.color = this.getAttribute("color") || defaults?.color;
657
658
 
658
659
  if (this.color) {
@@ -678,6 +679,7 @@ class FigSlider extends HTMLElement {
678
679
  type="number"
679
680
  min="${this.min}"
680
681
  max="${this.max}"
682
+ transform="${this.transform}"
681
683
  step="${this.step}"
682
684
  value="${this.value}">
683
685
  ${
@@ -727,7 +729,6 @@ class FigSlider extends HTMLElement {
727
729
 
728
730
  connectedCallback() {
729
731
  this.initialInnerHTML = this.innerHTML;
730
-
731
732
  this.#regenerateInnerHTML();
732
733
  }
733
734
  static get observedAttributes() {
@@ -740,6 +741,7 @@ class FigSlider extends HTMLElement {
740
741
  "disabled",
741
742
  "color",
742
743
  "units",
744
+ "transform",
743
745
  ];
744
746
  }
745
747
 
@@ -769,6 +771,12 @@ class FigSlider extends HTMLElement {
769
771
  this.figInputText.setAttribute("value", newValue);
770
772
  }
771
773
  break;
774
+ case "transform":
775
+ this.transform = Number(newValue) || 1;
776
+ if (this.figInputText) {
777
+ this.figInputText.setAttribute("transform", this.transform);
778
+ }
779
+ break;
772
780
  case "min":
773
781
  case "max":
774
782
  case "step":
@@ -821,12 +829,28 @@ class FigInputText extends HTMLElement {
821
829
  this.multiline = this.hasAttribute("multiline") || false;
822
830
  this.value = this.getAttribute("value") || "";
823
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
+ }
824
847
  this.placeholder = this.getAttribute("placeholder") || "";
825
-
826
848
  let html = `<input
827
849
  type="${this.type}"
828
850
  placeholder="${this.placeholder}"
829
- value="${this.value}" />`;
851
+ value="${
852
+ this.type === "number" ? this.#transformNumber(this.value) : this.value
853
+ }" />`;
830
854
  if (this.multiline) {
831
855
  html = `<textarea
832
856
  placeholder="${this.placeholder}">${this.value}</textarea>`;
@@ -850,23 +874,33 @@ class FigInputText extends HTMLElement {
850
874
 
851
875
  this.input = this.querySelector("input,textarea");
852
876
 
853
- if (this.getAttribute("min")) {
854
- this.input.setAttribute("min", this.getAttribute("min"));
855
- }
856
- if (this.getAttribute("max")) {
857
- this.input.setAttribute("max", this.getAttribute("max"));
858
- }
859
- if (this.getAttribute("step")) {
860
- this.input.setAttribute("step", this.getAttribute("step"));
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
+ }
861
887
  }
862
- this.input.addEventListener("input", this.handleInput.bind(this));
888
+ this.input.addEventListener("input", this.#handleInput.bind(this));
863
889
  });
864
890
  }
865
891
  focus() {
866
892
  this.input.focus();
867
893
  }
868
- handleInput() {
869
- this.value = this.input.value;
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
+ }
870
904
  }
871
905
 
872
906
  static get observedAttributes() {
@@ -879,6 +913,7 @@ class FigInputText extends HTMLElement {
879
913
  "step",
880
914
  "min",
881
915
  "max",
916
+ "transform",
882
917
  ];
883
918
  }
884
919
 
@@ -888,10 +923,23 @@ class FigInputText extends HTMLElement {
888
923
  case "disabled":
889
924
  this.disabled = this.input.disabled = newValue;
890
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;
891
935
  default:
892
- this[name] = this.input[name] = newValue;
936
+ let value = newValue;
937
+ if (this.type === "number") {
938
+ value = this.#transformNumber(value);
939
+ }
940
+ this[name] = this.input[name] = value;
893
941
  if (this.input) {
894
- this.input.setAttribute(name, newValue);
942
+ this.input.setAttribute(name, value);
895
943
  }
896
944
  break;
897
945
  }
@@ -1394,15 +1442,14 @@ class FigChit extends HTMLElement {
1394
1442
  this.value = this.getAttribute("value") || "";
1395
1443
  this.size = this.getAttribute("size") || "small";
1396
1444
  this.disabled = this.getAttribute("disabled") === "true" ? true : false;
1397
- this.variant = this.getAttribute("variant") || "square";
1398
1445
  this.innerHTML = `<input type="color" value="${this.value}" />`;
1446
+ this.#updateSrc(this.src);
1399
1447
 
1400
1448
  requestAnimationFrame(() => {
1401
1449
  this.input = this.querySelector("input");
1402
- this.updateSrc(this.src);
1403
1450
  });
1404
1451
  }
1405
- updateSrc(src) {
1452
+ #updateSrc(src) {
1406
1453
  if (src) {
1407
1454
  this.src = src;
1408
1455
  this.style.setProperty("--src", `url(${src})`);
@@ -1411,14 +1458,22 @@ class FigChit extends HTMLElement {
1411
1458
  }
1412
1459
  }
1413
1460
  static get observedAttributes() {
1414
- return ["type", "src", "size", "variant", "value", "disabled"];
1461
+ return ["src", "value", "disabled"];
1415
1462
  }
1416
1463
  attributeChangedCallback(name, oldValue, newValue) {
1417
- if (name === "src") {
1418
- this.updateSrc(newValue);
1419
- }
1420
- if (name === "disabled") {
1421
- this.disabled = newValue.toLowerCase() === "true";
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;
1422
1477
  }
1423
1478
  }
1424
1479
  }
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.82"
3
+ "version": "1.0.84"
4
4
  }