@rogieking/figui3 1.0.98 → 1.0.99

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/fig.css +1 -0
  2. package/fig.js +47 -5
  3. package/package.json +1 -1
package/fig.css CHANGED
@@ -2188,6 +2188,7 @@ fig-field,
2188
2188
  flex: 0;
2189
2189
  padding: var(--spacer-1) 0;
2190
2190
  display: flex;
2191
+ justify-content: space-between;
2191
2192
  min-height: calc(1rem + var(--spacer-1) * 2);
2192
2193
  align-items: center;
2193
2194
  }
package/fig.js CHANGED
@@ -842,9 +842,18 @@ class FigSlider extends HTMLElement {
842
842
  window.customElements.define("fig-slider", FigSlider);
843
843
 
844
844
  class FigInputText extends HTMLElement {
845
+ #boundMouseMove;
846
+ #boundMouseUp;
847
+ #boundMouseDown;
848
+
845
849
  constructor() {
846
850
  super();
851
+ // Pre-bind the event handlers once
852
+ this.#boundMouseMove = this.#handleMouseMove.bind(this);
853
+ this.#boundMouseUp = this.#handleMouseUp.bind(this);
854
+ this.#boundMouseDown = this.#handleMouseDown.bind(this);
847
855
  }
856
+
848
857
  connectedCallback() {
849
858
  this.multiline = this.hasAttribute("multiline") || false;
850
859
  this.value = this.getAttribute("value") || "";
@@ -904,6 +913,7 @@ class FigInputText extends HTMLElement {
904
913
  if (this.getAttribute("step")) {
905
914
  this.input.setAttribute("step", this.#transformNumber(this.step));
906
915
  }
916
+ this.addEventListener("pointerdown", this.#boundMouseDown);
907
917
  }
908
918
  this.input.addEventListener("input", this.#handleInput.bind(this));
909
919
  });
@@ -912,15 +922,47 @@ class FigInputText extends HTMLElement {
912
922
  this.input.focus();
913
923
  }
914
924
  #transformNumber(value) {
915
- return value * (this.transform || 1);
925
+ return Number(value) * (this.transform || 1);
916
926
  }
917
927
  #handleInput(e) {
918
928
  let value = e.target.value;
919
929
  if (this.type === "number") {
920
- this.value = value / (this.transform || 1);
921
- } else {
922
- this.value = value;
930
+ if (this.min) {
931
+ value = Math.min(this.min, value);
932
+ }
933
+ if (this.max) {
934
+ value = Math.max(this.max, value);
935
+ }
936
+ value = value / (this.transform || 1);
923
937
  }
938
+ this.value = value;
939
+ }
940
+ #handleMouseMove(e) {
941
+ if (e.altKey) {
942
+ const step = (this.step || 1) * e.movementX;
943
+ const value = Number(this.input.value) + step;
944
+ this.setAttribute("value", value / this.transform);
945
+ }
946
+ }
947
+ #handleMouseDown(e) {
948
+ if (e.altKey) {
949
+ this.input.style.cursor =
950
+ this.style.cursor =
951
+ document.body.style.cursor =
952
+ "ew-resize";
953
+ // Use the pre-bound handlers
954
+ window.addEventListener("pointermove", this.#boundMouseMove);
955
+ window.addEventListener("pointerup", this.#boundMouseUp);
956
+ }
957
+ }
958
+ #handleMouseUp(e) {
959
+ this.input.style.cursor =
960
+ this.style.cursor =
961
+ document.body.style.cursor =
962
+ "";
963
+ // Remove the pre-bound handlers
964
+ window.removeEventListener("pointermove", this.#boundMouseMove);
965
+ window.removeEventListener("pointerup", this.#boundMouseUp);
924
966
  }
925
967
 
926
968
  static get observedAttributes() {
@@ -1461,7 +1503,7 @@ class FigChit extends HTMLElement {
1461
1503
  this.src = this.getAttribute("src") || "";
1462
1504
  this.value = this.getAttribute("value") || "";
1463
1505
  this.size = this.getAttribute("size") || "small";
1464
- this.disabled = this.getAttribute("disabled") === "true" ? true : false;
1506
+ this.disabled = this.getAttribute("disabled") === "true";
1465
1507
  this.innerHTML = `<input type="color" value="${this.value}" />`;
1466
1508
  this.#updateSrc(this.src);
1467
1509
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.98",
3
+ "version": "1.0.99",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {