@rogieking/figui3 2.33.3 → 2.33.4

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 (2) hide show
  1. package/fig.js +40 -12
  2. package/package.json +1 -1
package/fig.js CHANGED
@@ -2726,6 +2726,7 @@ class FigInputText extends HTMLElement {
2726
2726
  #isInteracting = false;
2727
2727
  #boundMouseMove;
2728
2728
  #boundMouseUp;
2729
+ #boundWindowBlur;
2729
2730
  #boundMouseDown;
2730
2731
  #boundInputChange;
2731
2732
 
@@ -2734,6 +2735,7 @@ class FigInputText extends HTMLElement {
2734
2735
  // Pre-bind the event handlers once
2735
2736
  this.#boundMouseMove = this.#handleMouseMove.bind(this);
2736
2737
  this.#boundMouseUp = this.#handleMouseUp.bind(this);
2738
+ this.#boundWindowBlur = this.#handleMouseUp.bind(this);
2737
2739
  this.#boundMouseDown = this.#handleMouseDown.bind(this);
2738
2740
  this.#boundInputChange = (e) => {
2739
2741
  e.stopPropagation();
@@ -2831,6 +2833,7 @@ class FigInputText extends HTMLElement {
2831
2833
  this.removeEventListener("pointerdown", this.#boundMouseDown);
2832
2834
  window.removeEventListener("pointermove", this.#boundMouseMove);
2833
2835
  window.removeEventListener("pointerup", this.#boundMouseUp);
2836
+ window.removeEventListener("blur", this.#boundWindowBlur);
2834
2837
  }
2835
2838
 
2836
2839
  focus() {
@@ -2862,6 +2865,10 @@ class FigInputText extends HTMLElement {
2862
2865
  }
2863
2866
  #handleMouseMove(e) {
2864
2867
  if (this.type !== "number") return;
2868
+ if (e.buttons === 0) {
2869
+ this.#handleMouseUp();
2870
+ return;
2871
+ }
2865
2872
  let step = (this.step || 1) * e.movementX;
2866
2873
  let value = Number(this.input.value);
2867
2874
  value = value / (this.transform || 1) + step;
@@ -2885,6 +2892,7 @@ class FigInputText extends HTMLElement {
2885
2892
  this.style.userSelect = "none";
2886
2893
  window.addEventListener("pointermove", this.#boundMouseMove);
2887
2894
  window.addEventListener("pointerup", this.#boundMouseUp);
2895
+ window.addEventListener("blur", this.#boundWindowBlur);
2888
2896
  }
2889
2897
  }
2890
2898
  #handleMouseUp(e) {
@@ -2897,6 +2905,7 @@ class FigInputText extends HTMLElement {
2897
2905
  this.style.userSelect = "all";
2898
2906
  window.removeEventListener("pointermove", this.#boundMouseMove);
2899
2907
  window.removeEventListener("pointerup", this.#boundMouseUp);
2908
+ window.removeEventListener("blur", this.#boundWindowBlur);
2900
2909
  }
2901
2910
  #sanitizeInput(value, transform = true) {
2902
2911
  let sanitized = value;
@@ -3018,6 +3027,7 @@ customElements.define("fig-input-text", FigInputText);
3018
3027
  class FigInputNumber extends HTMLElement {
3019
3028
  #boundMouseMove;
3020
3029
  #boundMouseUp;
3030
+ #boundWindowBlur;
3021
3031
  #boundMouseDown;
3022
3032
  #boundInputChange;
3023
3033
  #boundInput;
@@ -3049,6 +3059,7 @@ class FigInputNumber extends HTMLElement {
3049
3059
  // Pre-bind the event handlers once
3050
3060
  this.#boundMouseMove = this.#handleMouseMove.bind(this);
3051
3061
  this.#boundMouseUp = this.#handleMouseUp.bind(this);
3062
+ this.#boundWindowBlur = this.#handleMouseUp.bind(this);
3052
3063
  this.#boundMouseDown = this.#handleMouseDown.bind(this);
3053
3064
  this.#boundInputChange = (e) => {
3054
3065
  e.stopPropagation();
@@ -3170,6 +3181,7 @@ class FigInputNumber extends HTMLElement {
3170
3181
  this.removeEventListener("pointerdown", this.#boundMouseDown);
3171
3182
  window.removeEventListener("pointermove", this.#boundMouseMove);
3172
3183
  window.removeEventListener("pointerup", this.#boundMouseUp);
3184
+ window.removeEventListener("blur", this.#boundWindowBlur);
3173
3185
  }
3174
3186
 
3175
3187
  focus() {
@@ -3322,6 +3334,10 @@ class FigInputNumber extends HTMLElement {
3322
3334
 
3323
3335
  #handleMouseMove(e) {
3324
3336
  if (this.disabled) return;
3337
+ if (e.buttons === 0) {
3338
+ this.#handleMouseUp();
3339
+ return;
3340
+ }
3325
3341
  let step = (this.step || 1) * e.movementX;
3326
3342
  let numericValue = this.#getNumericValue(this.input.value);
3327
3343
  let value = Number(numericValue) / (this.transform || 1) + step;
@@ -3343,6 +3359,7 @@ class FigInputNumber extends HTMLElement {
3343
3359
  this.style.userSelect = "none";
3344
3360
  window.addEventListener("pointermove", this.#boundMouseMove);
3345
3361
  window.addEventListener("pointerup", this.#boundMouseUp);
3362
+ window.addEventListener("blur", this.#boundWindowBlur);
3346
3363
  }
3347
3364
  }
3348
3365
 
@@ -3355,6 +3372,7 @@ class FigInputNumber extends HTMLElement {
3355
3372
  this.style.userSelect = "all";
3356
3373
  window.removeEventListener("pointermove", this.#boundMouseMove);
3357
3374
  window.removeEventListener("pointerup", this.#boundMouseUp);
3375
+ window.removeEventListener("blur", this.#boundWindowBlur);
3358
3376
  }
3359
3377
 
3360
3378
  #sanitizeInput(value, transform = true) {
@@ -8240,6 +8258,12 @@ class FigFillPicker extends HTMLElement {
8240
8258
  #setupColorAreaEvents() {
8241
8259
  if (!this.#colorArea || !this.#colorAreaHandle) return;
8242
8260
 
8261
+ const endColorDrag = () => {
8262
+ if (!this.#isDraggingColor) return;
8263
+ this.#isDraggingColor = false;
8264
+ this.#emitChange();
8265
+ };
8266
+
8243
8267
  const updateFromEvent = (e) => {
8244
8268
  const rect = this.#colorArea.getBoundingClientRect();
8245
8269
  const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
@@ -8261,15 +8285,17 @@ class FigFillPicker extends HTMLElement {
8261
8285
  });
8262
8286
 
8263
8287
  this.#colorArea.addEventListener("pointermove", (e) => {
8264
- if (this.#isDraggingColor) {
8265
- updateFromEvent(e);
8288
+ if (!this.#isDraggingColor) return;
8289
+ if (e.buttons === 0) {
8290
+ endColorDrag();
8291
+ return;
8266
8292
  }
8293
+ updateFromEvent(e);
8267
8294
  });
8268
8295
 
8269
- this.#colorArea.addEventListener("pointerup", () => {
8270
- this.#isDraggingColor = false;
8271
- this.#emitChange();
8272
- });
8296
+ this.#colorArea.addEventListener("pointerup", endColorDrag);
8297
+ this.#colorArea.addEventListener("pointercancel", endColorDrag);
8298
+ this.#colorArea.addEventListener("lostpointercapture", endColorDrag);
8273
8299
 
8274
8300
  // Handle drag (for when handle is at corners)
8275
8301
  this.#colorAreaHandle.addEventListener("pointerdown", (e) => {
@@ -8279,15 +8305,17 @@ class FigFillPicker extends HTMLElement {
8279
8305
  });
8280
8306
 
8281
8307
  this.#colorAreaHandle.addEventListener("pointermove", (e) => {
8282
- if (this.#isDraggingColor) {
8283
- updateFromEvent(e);
8308
+ if (!this.#isDraggingColor) return;
8309
+ if (e.buttons === 0) {
8310
+ endColorDrag();
8311
+ return;
8284
8312
  }
8313
+ updateFromEvent(e);
8285
8314
  });
8286
8315
 
8287
- this.#colorAreaHandle.addEventListener("pointerup", () => {
8288
- this.#isDraggingColor = false;
8289
- this.#emitChange();
8290
- });
8316
+ this.#colorAreaHandle.addEventListener("pointerup", endColorDrag);
8317
+ this.#colorAreaHandle.addEventListener("pointercancel", endColorDrag);
8318
+ this.#colorAreaHandle.addEventListener("lostpointercapture", endColorDrag);
8291
8319
  }
8292
8320
 
8293
8321
  #updateColorInputs() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "2.33.3",
3
+ "version": "2.33.4",
4
4
  "description": "A lightweight web components library for building Figma plugin and widget UIs with native look and feel",
5
5
  "author": "Rogie King",
6
6
  "license": "MIT",