tgui-core 2.0.3 → 2.0.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.
@@ -37,8 +37,6 @@ type Props = {
37
37
  step: number;
38
38
  /** The step size in pixels. */
39
39
  stepPixelSize: number;
40
- /** The number of milliseconds to suppress flickering. */
41
- suppressFlicker: number;
42
40
  /** Whether to unclamp the value. */
43
41
  unclamped: boolean;
44
42
  /** The unit of the value. */
@@ -1,132 +1,111 @@
1
- import { jsxs as W, Fragment as Z, jsx as P } from "react/jsx-runtime";
2
- import { useState as y, useRef as c, useEffect as C } from "react";
3
- import { KEY as Y } from "../common/keys.js";
4
- import { clamp as F } from "../common/math.js";
5
- import { AnimatedNumber as ee } from "./AnimatedNumber.js";
6
- const te = 400;
7
- function K(r, p) {
8
- return r.screenX * p[0] + r.screenY * p[1];
1
+ import { jsxs as $, Fragment as q, jsx as D } from "react/jsx-runtime";
2
+ import { useState as F, useRef as i, useEffect as J } from "react";
3
+ import { KEY as Q, isEscape as W } from "../common/keys.js";
4
+ import { clamp as b } from "../common/math.js";
5
+ import { AnimatedNumber as Z } from "./AnimatedNumber.js";
6
+ const C = 400, x = -1;
7
+ function A(n, m) {
8
+ return n.screenX * m[0] + n.screenY * m[1];
9
9
  }
10
- function se(r) {
10
+ function ie(n) {
11
11
  const {
12
12
  // Our props
13
- animated: p,
14
- children: M,
15
- dragMatrix: V = [1, 0],
16
- format: E,
17
- maxValue: g = Number.POSITIVE_INFINITY,
18
- minValue: l = Number.NEGATIVE_INFINITY,
19
- onChange: s,
20
- onDrag: a,
21
- step: o = 1,
13
+ animated: m,
14
+ children: L,
15
+ dragMatrix: S = [1, 0],
16
+ format: g,
17
+ maxValue: N = Number.POSITIVE_INFINITY,
18
+ minValue: o = Number.NEGATIVE_INFINITY,
19
+ onChange: a,
20
+ onDrag: l,
21
+ step: s = 1,
22
22
  stepPixelSize: O = 1,
23
- suppressFlicker: S = 50,
24
- unclamped: j,
25
- unit: h,
26
- updateRate: w = te,
23
+ unclamped: Y,
24
+ unit: V,
25
+ updateRate: k = C,
27
26
  // Box props
28
- fontSize: z,
29
- height: B,
27
+ fontSize: K,
28
+ height: P,
30
29
  lineHeight: U
31
- } = r, [G, T] = y(r.value), [v, f] = y(!1), [k, D] = y(!1), i = c(!1), n = c(0), m = c(0), R = c(null), N = c(null), I = c(null), b = c(null);
32
- C(() => {
33
- T(r.value);
34
- }, [r.value]);
35
- function _(e) {
36
- if (document.body.style["pointer-events"] = "auto", b.current && clearTimeout(b.current), I.current && clearInterval(I.current), i.current = !1, f(!1), m.current = 0, document.removeEventListener("mousemove", x), document.removeEventListener("mouseup", _), L(), s == null || s(e, n.current), a == null || a(e, n.current), N.current) {
37
- const t = N.current;
38
- t.value = n.toString(), setTimeout(() => {
30
+ } = n, [ee, I] = F(n.value), [d, v] = F(!1), r = i(!1), u = i(n.value), c = i(0), E = i(x), y = i(null), T = i(null), p = i(null);
31
+ J(() => {
32
+ n.value !== u.current && (u.current = n.value, I(n.value));
33
+ }, [n.value]);
34
+ function j(e) {
35
+ d || (document.body.style["pointer-events"] = "none", E.current = A(e.nativeEvent, S), c.current = n.value, r.current = !0, document.addEventListener("mouseup", _), p.current = setTimeout(() => {
36
+ w(e.nativeEvent);
37
+ }, 100));
38
+ }
39
+ function w(e) {
40
+ if (r.current)
41
+ document.addEventListener("mousemove", h), T.current = setInterval(() => {
42
+ r.current && (l == null || l(e, n.value));
43
+ }, k);
44
+ else if (v(!0), y.current) {
45
+ const t = y.current;
46
+ t.value = c.current.toString(), setTimeout(() => {
39
47
  t.focus(), t.select();
40
48
  }, 10);
41
49
  }
50
+ p.current && clearTimeout(p.current);
42
51
  }
43
- function x(e) {
44
- if (!m.current) return;
45
- const t = K(e, V), u = t - m.current;
46
- if (!i.current) {
47
- Math.abs(u) > 4 && (i.current = !0);
48
- return;
49
- }
50
- const Q = Number.isFinite(l) ? l % o : 0;
51
- n.current = F(
52
- n.current + u * o / O,
53
- l - o,
54
- g + o
55
- ), T(
56
- F(
57
- n.current - n.current % o + Q,
58
- l,
59
- g
60
- )
61
- ), m.current = t;
52
+ function h(e) {
53
+ const t = A(e, S), H = t - E.current, X = Number.isFinite(o) ? o % s : 0;
54
+ c.current = b(
55
+ c.current + H * s / O,
56
+ o - s,
57
+ N + s
58
+ );
59
+ const R = b(
60
+ c.current - c.current % s + X,
61
+ o,
62
+ N
63
+ );
64
+ u.current = R, I(R), E.current = t;
62
65
  }
63
- function H(e) {
64
- if (v) return;
65
- const t = e.nativeEvent;
66
- document.body.style["pointer-events"] = "none", m.current = K(t, V), n.current = r.value, b.current = setTimeout(() => {
67
- i.current = !0;
68
- }, 250), I.current = setInterval(() => {
69
- i && (a == null || a(t, r.value));
70
- }, w), document.addEventListener("mousemove", x), document.addEventListener("mouseup", _);
66
+ function _(e) {
67
+ document.body.style["pointer-events"] = "auto", T.current && clearInterval(T.current), E.current = x, document.removeEventListener("mousemove", h), document.removeEventListener("mouseup", _), r.current && (a == null || a(e, u.current), l == null || l(e, u.current), r.current = !1);
71
68
  }
72
- function X(e) {
73
- if (e.key === Y.Enter) {
74
- e.preventDefault(), e.stopPropagation(), A(e.nativeEvent, e.currentTarget.value);
75
- return;
76
- }
77
- if (e.key === Y.Escape) {
78
- f(!1);
79
- return;
80
- }
69
+ function z(e) {
70
+ (e.key === Q.Enter || W(e.key)) && v(!1);
81
71
  }
82
- function A(e, t) {
83
- let u = Number.parseFloat(t);
84
- if (j || (u = F(u, l, g)), Number.isNaN(u)) {
85
- f(!1);
72
+ function B(e) {
73
+ let t = Number.parseFloat(e.currentTarget.value);
74
+ if (Y || (t = b(t, o, N)), Number.isNaN(t)) {
75
+ v(!1);
86
76
  return;
87
77
  }
88
- f(!1), T(u), n.current = u, L(), s == null || s(e, u);
89
- }
90
- function L() {
91
- if (S <= 0) return;
92
- const e = R.current;
93
- if (e)
94
- return D(!0), clearTimeout(e), R.current = setTimeout(() => {
95
- D(!1);
96
- }, S), () => clearTimeout(e);
97
- }
98
- function $(e) {
99
- v && f(!1), A(e.nativeEvent, e.currentTarget.value);
78
+ c.current = t, u.current = t, I(t), a == null || a(e.nativeEvent, t), d && v(!1);
100
79
  }
101
- let d = r.value;
102
- (i.current || k) && (d = G);
103
- const q = /* @__PURE__ */ W(Z, { children: [
104
- p && !i.current && !k ? /* @__PURE__ */ P(ee, { value: d, format: E }) : E ? E(d) : d,
105
- h ? ` ${h}` : ""
106
- ] }), J = /* @__PURE__ */ P(
80
+ let f = n.value;
81
+ r.current && (f = u.current);
82
+ const G = /* @__PURE__ */ $(q, { children: [
83
+ m && !r.current ? /* @__PURE__ */ D(Z, { value: f, format: g }) : g ? g(f) : f,
84
+ V ? ` ${V}` : ""
85
+ ] }), M = /* @__PURE__ */ D(
107
86
  "input",
108
87
  {
109
- ref: N,
88
+ ref: y,
110
89
  className: "NumberInput__input",
111
90
  style: {
112
- display: v ? void 0 : "none",
113
- height: B,
91
+ display: d ? void 0 : "none",
92
+ height: P,
114
93
  lineHeight: U,
115
- fontSize: z
94
+ fontSize: K
116
95
  },
117
- onBlur: $,
118
- onKeyDown: X
96
+ onBlur: B,
97
+ onKeyDown: z
119
98
  }
120
99
  );
121
- return M({
122
- displayElement: q,
123
- displayValue: d,
124
- dragging: i.current,
125
- editing: v,
126
- handleDragStart: H,
127
- inputElement: J
100
+ return L({
101
+ displayElement: G,
102
+ displayValue: f,
103
+ dragging: r.current,
104
+ editing: d,
105
+ handleDragStart: j,
106
+ inputElement: M
128
107
  });
129
108
  }
130
109
  export {
131
- se as DraggableControl
110
+ ie as DraggableControl
132
111
  };
@@ -1,4 +1,4 @@
1
- import { Component, HTMLAttributes, PropsWithChildren, RefObject } from 'react';
1
+ import { Component, HTMLAttributes, PropsWithChildren } from 'react';
2
2
  type Props = {
3
3
  acceptableDifference?: number;
4
4
  maxFontSize: number;
@@ -9,7 +9,7 @@ type State = {
9
9
  fontSize: number;
10
10
  };
11
11
  export declare class FitText extends Component<Props, State> {
12
- ref: RefObject<HTMLDivElement | null>;
12
+ ref: import('react').RefObject<HTMLDivElement | null>;
13
13
  state: State;
14
14
  constructor(props: Props);
15
15
  componentDidUpdate(prevProps: any): void;
@@ -1,4 +1,4 @@
1
- import { CSSProperties, Component, FocusEventHandler, KeyboardEventHandler, MouseEventHandler, RefObject } from 'react';
1
+ import { CSSProperties, Component, FocusEventHandler, KeyboardEventHandler, MouseEventHandler } from 'react';
2
2
  import { BooleanLike } from '../common/react';
3
3
  import { BoxProps } from './Box';
4
4
  type Props = Required<{
@@ -51,7 +51,7 @@ type State = {
51
51
  * to fine tune the value, or single click it to manually type a number.
52
52
  */
53
53
  export declare class NumberInput extends Component<Props, State> {
54
- inputRef: RefObject<HTMLInputElement | null>;
54
+ inputRef: import('react').RefObject<HTMLInputElement | null>;
55
55
  dragTimeout: NodeJS.Timeout;
56
56
  dragInterval: NodeJS.Timeout;
57
57
  state: State;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tgui-core",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "TGUI core component library",
5
5
  "keywords": ["TGUI", "library", "typescript"],
6
6
  "files": ["dist", "styles"],
@@ -14,4 +14,5 @@ $border-radius: 0 !default;
14
14
  padding: var(--space-m) var(--space-l);
15
15
  pointer-events: none;
16
16
  text-align: left;
17
+ width: max-content;
17
18
  }