tgui-core 1.2.0 → 1.3.0

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 (116) hide show
  1. package/README.md +3 -3
  2. package/dist/common/color.js +31 -30
  3. package/dist/common/events.js +5 -5
  4. package/dist/common/format.js +27 -27
  5. package/dist/common/hotkeys.d.ts +0 -1
  6. package/dist/common/hotkeys.js +2 -2
  7. package/dist/common/math.d.ts +4 -0
  8. package/dist/common/math.js +29 -25
  9. package/dist/common/random.js +14 -13
  10. package/dist/common/react.js +1 -1
  11. package/dist/common/string.js +9 -9
  12. package/dist/common/type-utils.d.ts +1 -1
  13. package/dist/components/AnimatedNumber.d.ts +6 -6
  14. package/dist/components/AnimatedNumber.js +14 -17
  15. package/dist/components/Autofocus.d.ts +0 -1
  16. package/dist/components/Blink.d.ts +0 -1
  17. package/dist/components/BlockQuote.d.ts +0 -1
  18. package/dist/components/BlockQuote.js +4 -7
  19. package/dist/components/Box.d.ts +0 -1
  20. package/dist/components/Box.js +4 -4
  21. package/dist/components/Button.d.ts +0 -1
  22. package/dist/components/Button.js +173 -211
  23. package/dist/components/ByondUi.js +3 -3
  24. package/dist/components/Chart.d.ts +0 -1
  25. package/dist/components/Chart.js +25 -22
  26. package/dist/components/Collapsible.d.ts +0 -1
  27. package/dist/components/ColorBox.d.ts +0 -1
  28. package/dist/components/ColorBox.js +7 -14
  29. package/dist/components/Dialog.js +31 -40
  30. package/dist/components/Dimmer.d.ts +0 -1
  31. package/dist/components/Dimmer.js +6 -9
  32. package/dist/components/Divider.js +10 -14
  33. package/dist/components/DmIcon.d.ts +0 -1
  34. package/dist/components/DraggableControl.js +57 -49
  35. package/dist/components/Dropdown.d.ts +0 -1
  36. package/dist/components/Dropdown.js +73 -67
  37. package/dist/components/FitText.d.ts +0 -1
  38. package/dist/components/Flex.d.ts +1 -1
  39. package/dist/components/Flex.js +39 -41
  40. package/dist/components/Icon.d.ts +0 -1
  41. package/dist/components/Icon.js +27 -34
  42. package/dist/components/Image.d.ts +0 -1
  43. package/dist/components/Image.js +7 -6
  44. package/dist/components/ImageButton.d.ts +0 -1
  45. package/dist/components/ImageButton.js +84 -171
  46. package/dist/components/InfinitePlane.js +1 -1
  47. package/dist/components/Input.d.ts +0 -1
  48. package/dist/components/Input.js +57 -64
  49. package/dist/components/KeyListener.d.ts +0 -1
  50. package/dist/components/Knob.d.ts +0 -1
  51. package/dist/components/Knob.js +91 -117
  52. package/dist/components/LabeledControls.d.ts +0 -1
  53. package/dist/components/LabeledList.d.ts +0 -1
  54. package/dist/components/LabeledList.js +48 -55
  55. package/dist/components/MenuBar.d.ts +0 -1
  56. package/dist/components/MenuBar.js +93 -102
  57. package/dist/components/Modal.d.ts +0 -1
  58. package/dist/components/Modal.js +11 -18
  59. package/dist/components/NoticeBox.d.ts +0 -1
  60. package/dist/components/NoticeBox.js +16 -43
  61. package/dist/components/NumberInput.d.ts +0 -2
  62. package/dist/components/NumberInput.js +99 -107
  63. package/dist/components/Popper.d.ts +0 -1
  64. package/dist/components/ProgressBar.d.ts +0 -1
  65. package/dist/components/ProgressBar.js +22 -27
  66. package/dist/components/RestrictedInput.js +64 -58
  67. package/dist/components/RoundGauge.d.ts +0 -1
  68. package/dist/components/RoundGauge.js +70 -104
  69. package/dist/components/Section.d.ts +1 -2
  70. package/dist/components/Section.js +50 -51
  71. package/dist/components/Slider.d.ts +0 -1
  72. package/dist/components/Slider.js +72 -80
  73. package/dist/components/Stack.d.ts +0 -1
  74. package/dist/components/Stack.js +37 -47
  75. package/dist/components/StyleableSection.d.ts +0 -1
  76. package/dist/components/StyleableSection.js +11 -11
  77. package/dist/components/Table.d.ts +0 -1
  78. package/dist/components/Table.js +38 -47
  79. package/dist/components/Tabs.d.ts +0 -1
  80. package/dist/components/Tabs.js +43 -75
  81. package/dist/components/TextArea.d.ts +0 -1
  82. package/dist/components/TextArea.js +74 -69
  83. package/dist/components/TimeDisplay.d.ts +7 -6
  84. package/dist/components/TimeDisplay.js +17 -17
  85. package/dist/components/Tooltip.d.ts +1 -2
  86. package/dist/components/Tooltip.js +8 -10
  87. package/dist/components/TrackOutsideClicks.d.ts +0 -1
  88. package/dist/components/VirtualList.d.ts +0 -1
  89. package/package.json +11 -25
  90. package/dist/ProgressBar.module-Jzqlebbx.js +0 -29
  91. package/dist/Section.module-qhQWhlUX.js +0 -18
  92. package/dist/assets/BlockQuote.css +0 -1
  93. package/dist/assets/Button.css +0 -1
  94. package/dist/assets/ColorBox.css +0 -1
  95. package/dist/assets/Dialog.css +0 -1
  96. package/dist/assets/Dimmer.css +0 -1
  97. package/dist/assets/Divider.css +0 -1
  98. package/dist/assets/Flex.css +0 -1
  99. package/dist/assets/Icon.css +0 -6
  100. package/dist/assets/ImageButton.css +0 -5
  101. package/dist/assets/Input.css +0 -1
  102. package/dist/assets/Knob.css +0 -1
  103. package/dist/assets/LabeledList.css +0 -1
  104. package/dist/assets/MenuBar.css +0 -1
  105. package/dist/assets/Modal.css +0 -1
  106. package/dist/assets/NoticeBox.css +0 -1
  107. package/dist/assets/NumberInput.css +0 -1
  108. package/dist/assets/ProgressBar.css +0 -1
  109. package/dist/assets/RoundGauge.css +0 -1
  110. package/dist/assets/Section.css +0 -1
  111. package/dist/assets/Slider.css +0 -1
  112. package/dist/assets/Stack.css +0 -1
  113. package/dist/assets/Table.css +0 -1
  114. package/dist/assets/Tabs.css +0 -1
  115. package/dist/assets/TextArea.css +0 -1
  116. package/dist/assets/Tooltip.css +0 -1
@@ -1,44 +1,36 @@
1
- import '../assets/NumberInput.css';var N = Object.defineProperty;
2
- var w = (c, d, e) => d in c ? N(c, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[d] = e;
3
- var l = (c, d, e) => w(c, typeof d != "symbol" ? d + "" : d, e);
4
- import { jsxs as _, jsx as V } from "react/jsx-runtime";
5
- import { Component as E, createRef as I } from "react";
6
- import { KEY as D, isEscape as M } from "../common/keys.js";
7
- import { clamp as g, round as T } from "../common/math.js";
8
- import { classes as F } from "../common/react.js";
9
- import { AnimatedNumber as R } from "./AnimatedNumber.js";
10
- import { Box as Y } from "./Box.js";
11
- const B = "_numberInput_4xyrw_20", K = "_fluid_4xyrw_36", L = "_content_4xyrw_40", z = "_barContainer_4xyrw_44", j = "_bar_4xyrw_44", k = "_inner_4xyrw_61", p = {
12
- numberInput: B,
13
- fluid: K,
14
- content: L,
15
- barContainer: z,
16
- bar: j,
17
- inner: k
18
- };
19
- class J extends E {
20
- constructor(e) {
21
- super(e);
1
+ var I = Object.defineProperty;
2
+ var E = (m, d, e) => d in m ? I(m, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[d] = e;
3
+ var o = (m, d, e) => E(m, typeof d != "symbol" ? d + "" : d, e);
4
+ import { jsxs as N, jsx as f } from "react/jsx-runtime";
5
+ import { Component as x, createRef as D } from "react";
6
+ import { KEY as _, isEscape as M } from "../common/keys.js";
7
+ import { clamp as h, round as T } from "../common/math.js";
8
+ import { classes as w } from "../common/react.js";
9
+ import { AnimatedNumber as F } from "./AnimatedNumber.js";
10
+ import { Box as R } from "./Box.js";
11
+ class H extends x {
12
+ constructor() {
13
+ super(...arguments);
22
14
  // Ref to the input field to set focus & highlight
23
- l(this, "inputRef", I());
15
+ o(this, "inputRef", D());
24
16
  // After this time has elapsed we are in drag mode so no editing when dragging ends
25
- l(this, "dragTimeout");
17
+ o(this, "dragTimeout");
26
18
  // Call onDrag at this interval
27
- l(this, "dragInterval");
19
+ o(this, "dragInterval");
28
20
  // default values for the number input state
29
- l(this, "state", {
21
+ o(this, "state", {
30
22
  editing: !1,
31
23
  dragging: !1,
32
24
  currentValue: 0,
33
25
  previousValue: 0,
34
26
  origin: 0
35
27
  });
36
- l(this, "handleDragStart", (e) => {
37
- const { value: o, disabled: a } = this.props, { editing: s } = this.state;
38
- if (a || s)
28
+ o(this, "handleDragStart", (e) => {
29
+ const { value: u, disabled: n } = this.props, { editing: s } = this.state;
30
+ if (n || s)
39
31
  return;
40
32
  document.body.style["pointer-events"] = "none";
41
- const r = parseFloat(o.toString());
33
+ const r = Number.parseFloat(u.toString());
42
34
  this.setState({
43
35
  dragging: !1,
44
36
  origin: e.screenY,
@@ -49,59 +41,59 @@ class J extends E {
49
41
  dragging: !0
50
42
  });
51
43
  }, 250), this.dragInterval = setInterval(() => {
52
- const { dragging: u, currentValue: i, previousValue: t } = this.state, { onDrag: n } = this.props;
53
- u && i !== t && (this.setState({
44
+ const { dragging: l, currentValue: i, previousValue: t } = this.state, { onDrag: a } = this.props;
45
+ l && i !== t && (this.setState({
54
46
  previousValue: i
55
- }), n == null || n(i));
47
+ }), a == null || a(i));
56
48
  }, 400), document.addEventListener("mousemove", this.handleDragMove), document.addEventListener("mouseup", this.handleDragEnd);
57
49
  });
58
- l(this, "handleDragMove", (e) => {
59
- const { minValue: o, maxValue: a, step: s, stepPixelSize: r, disabled: u } = this.props;
60
- u || this.setState((i) => {
61
- const t = { ...i }, n = t.origin - e.screenY;
50
+ o(this, "handleDragMove", (e) => {
51
+ const { minValue: u, maxValue: n, step: s, stepPixelSize: r, disabled: l } = this.props;
52
+ l || this.setState((i) => {
53
+ const t = { ...i }, a = t.origin - e.screenY;
62
54
  if (i.dragging) {
63
- const f = r || 1, m = g(
64
- t.currentValue + n * s / f,
65
- o - s,
66
- a + s
55
+ const g = r || 1, c = h(
56
+ t.currentValue + a * s / g,
57
+ u - s,
58
+ n + s
67
59
  );
68
- Math.abs(m - t.currentValue) >= s ? (t.currentValue = g(
69
- T(m / s, 0) * s,
70
- o,
71
- a
72
- ), t.origin = e.screenY) : Math.abs(n) > f && (t.origin = e.screenY);
73
- } else Math.abs(n) > 4 && (t.dragging = !0);
60
+ Math.abs(c - t.currentValue) >= s ? (t.currentValue = h(
61
+ T(c / s, 0) * s,
62
+ u,
63
+ n
64
+ ), t.origin = e.screenY) : Math.abs(a) > g && (t.origin = e.screenY);
65
+ } else Math.abs(a) > 4 && (t.dragging = !0);
74
66
  return t;
75
67
  });
76
68
  });
77
- l(this, "handleDragEnd", (e) => {
78
- const { dragging: o, currentValue: a } = this.state, { onDrag: s, onChange: r, disabled: u } = this.props;
79
- if (!u) {
69
+ o(this, "handleDragEnd", (e) => {
70
+ const { dragging: u, currentValue: n } = this.state, { onDrag: s, onChange: r, disabled: l } = this.props;
71
+ if (!l) {
80
72
  if (document.body.style["pointer-events"] = "auto", clearInterval(this.dragInterval), clearTimeout(this.dragTimeout), this.setState({
81
73
  dragging: !1,
82
- editing: !o,
83
- previousValue: a
84
- }), o)
85
- r == null || r(a), s == null || s(a);
74
+ editing: !u,
75
+ previousValue: n
76
+ }), u)
77
+ r == null || r(n), s == null || s(n);
86
78
  else if (this.inputRef) {
87
79
  const i = this.inputRef.current;
88
- i && (i.value = `${a}`, setTimeout(() => {
80
+ i && (i.value = `${n}`, setTimeout(() => {
89
81
  i.focus(), i.select();
90
82
  }, 10));
91
83
  }
92
84
  document.removeEventListener("mousemove", this.handleDragMove), document.removeEventListener("mouseup", this.handleDragEnd);
93
85
  }
94
86
  });
95
- l(this, "handleBlur", (e) => {
96
- const { editing: o, previousValue: a } = this.state, { minValue: s, maxValue: r, onChange: u, onDrag: i, disabled: t } = this.props;
97
- if (t || !o)
87
+ o(this, "handleBlur", (e) => {
88
+ const { editing: u, previousValue: n } = this.state, { minValue: s, maxValue: r, onChange: l, onDrag: i, disabled: t } = this.props;
89
+ if (t || !u)
98
90
  return;
99
- const n = g(
100
- parseFloat(e.target.value),
91
+ const a = h(
92
+ Number.parseFloat(e.target.value),
101
93
  s,
102
94
  r
103
95
  );
104
- if (isNaN(n)) {
96
+ if (Number.isNaN(a)) {
105
97
  this.setState({
106
98
  editing: !1
107
99
  });
@@ -109,22 +101,22 @@ class J extends E {
109
101
  }
110
102
  this.setState({
111
103
  editing: !1,
112
- currentValue: n,
113
- previousValue: n
114
- }), a !== n && (u == null || u(n), i == null || i(n));
104
+ currentValue: a,
105
+ previousValue: a
106
+ }), n !== a && (l == null || l(a), i == null || i(a));
115
107
  });
116
- l(this, "handleKeyDown", (e) => {
117
- const { minValue: o, maxValue: a, onChange: s, onDrag: r, disabled: u } = this.props;
118
- if (u)
108
+ o(this, "handleKeyDown", (e) => {
109
+ const { minValue: u, maxValue: n, onChange: s, onDrag: r, disabled: l } = this.props;
110
+ if (l)
119
111
  return;
120
112
  const { previousValue: i } = this.state;
121
- if (e.key === D.Enter) {
122
- const t = g(
123
- parseFloat(e.currentTarget.value),
124
- o,
125
- a
113
+ if (e.key === _.Enter) {
114
+ const t = h(
115
+ Number.parseFloat(e.currentTarget.value),
116
+ u,
117
+ n
126
118
  );
127
- if (isNaN(t)) {
119
+ if (Number.isNaN(t)) {
128
120
  this.setState({
129
121
  editing: !1
130
122
  });
@@ -141,71 +133,71 @@ class J extends E {
141
133
  });
142
134
  }
143
135
  componentDidMount() {
144
- const e = parseFloat(this.props.value.toString());
136
+ const e = Number.parseFloat(this.props.value.toString());
145
137
  this.setState({
146
138
  currentValue: e,
147
139
  previousValue: e
148
140
  });
149
141
  }
150
142
  render() {
151
- const { dragging: e, editing: o, currentValue: a } = this.state, {
143
+ const { dragging: e, editing: u, currentValue: n } = this.state, {
152
144
  className: s,
153
145
  fluid: r,
154
- animated: u,
146
+ animated: l,
155
147
  unit: i,
156
148
  value: t,
157
- minValue: n,
158
- maxValue: f,
159
- height: m,
149
+ minValue: a,
150
+ maxValue: g,
151
+ height: c,
160
152
  width: S,
161
- lineHeight: b,
162
- fontSize: y,
163
- format: v
153
+ lineHeight: v,
154
+ fontSize: b,
155
+ format: V
164
156
  } = this.props;
165
- let h = parseFloat(t.toString());
166
- e && (h = a);
167
- const x = /* @__PURE__ */ _("div", { className: p.content, children: [
168
- u && !e ? /* @__PURE__ */ V(R, { value: h, format: v }) : v ? v(h) : h,
169
- i ? " " + i : ""
157
+ let p = Number.parseFloat(t.toString());
158
+ e && (p = n);
159
+ const y = /* @__PURE__ */ N("div", { className: "NumberInput__content", children: [
160
+ l && !e ? /* @__PURE__ */ f(F, { value: p, format: V }) : V ? V(p) : p,
161
+ i ? ` ${i}` : ""
170
162
  ] });
171
- return /* @__PURE__ */ _(
172
- Y,
163
+ return /* @__PURE__ */ N(
164
+ R,
173
165
  {
174
- className: F([
175
- p.numberInput,
176
- r && p.fluid,
166
+ className: w([
167
+ "NumberInput",
168
+ r && "NumberInput--fluid",
177
169
  s
178
170
  ]),
179
171
  minWidth: S,
180
- minHeight: m,
181
- lineHeight: b,
182
- fontSize: y,
172
+ minHeight: c,
173
+ lineHeight: v,
174
+ fontSize: b,
183
175
  onMouseDown: this.handleDragStart,
184
176
  children: [
185
- /* @__PURE__ */ V("div", { className: p.barContainer, children: /* @__PURE__ */ V(
177
+ /* @__PURE__ */ f("div", { className: "NumberInput__barContainer", children: /* @__PURE__ */ f(
186
178
  "div",
187
179
  {
188
- className: p.bar,
180
+ className: "NumberInput__bar",
189
181
  style: {
190
- height: g(
191
- (h - n) / (f - n) * 100,
182
+ height: `${h(
183
+ (p - a) / (g - a) * 100,
192
184
  0,
193
185
  100
194
- ) + "%"
186
+ )}%`
195
187
  }
196
188
  }
197
189
  ) }),
198
- x,
199
- /* @__PURE__ */ V(
190
+ y,
191
+ /* @__PURE__ */ f(
200
192
  "input",
201
193
  {
202
194
  ref: this.inputRef,
203
- className: p.inner,
195
+ className: "NumberInput__input",
204
196
  style: {
205
- display: o ? "inline" : "none",
206
- height: m,
207
- lineHeight: b,
208
- fontSize: y
197
+ display: u ? "inline" : "none",
198
+ height: c,
199
+ lineHeight: v,
200
+ fontSize: b
209
201
  },
210
202
  onBlur: this.handleBlur,
211
203
  onKeyDown: this.handleKeyDown
@@ -217,5 +209,5 @@ class J extends E {
217
209
  }
218
210
  }
219
211
  export {
220
- J as NumberInput
212
+ H as NumberInput
221
213
  };
@@ -1,6 +1,5 @@
1
1
  import { Placement } from '@popperjs/core';
2
2
  import { PropsWithChildren, ReactNode } from 'react';
3
-
4
3
  type RequiredProps = {
5
4
  /** The content to display in the popper */
6
5
  content: ReactNode;
@@ -1,6 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { BoxProps } from './Box';
3
-
4
3
  type Props = {
5
4
  /**
6
5
  * Current progress as a floating point number between `minValue` (default: 0) and `maxValue` (default: 1).
@@ -1,37 +1,32 @@
1
- import { jsxs as x, jsx as n } from "react/jsx-runtime";
2
- import { CSS_COLORS as v } from "../common/constants.js";
3
- import { keyOfMatchingRange as y, toFixed as N, scale as S, clamp01 as _ } from "../common/math.js";
4
- import { classes as m } from "../common/react.js";
5
- import { p as e } from "../ProgressBar.module-Jzqlebbx.js";
6
- import { computeBoxProps as B, computeBoxClassName as O } from "./Box.js";
7
- function w(d) {
1
+ import { jsxs as B, jsx as i } from "react/jsx-runtime";
2
+ import { CSS_COLORS as C } from "../common/constants.js";
3
+ import { keyOfMatchingRange as P, toFixed as h, scale as x, clamp01 as _ } from "../common/math.js";
4
+ import { classes as v } from "../common/react.js";
5
+ import { computeBoxProps as y, computeBoxClassName as N } from "./Box.js";
6
+ function j(n) {
8
7
  const {
9
- className: f,
10
- value: r,
11
- minValue: p = 0,
12
- maxValue: u = 1,
13
- color: C,
14
- ranges: g = {},
15
- children: l,
16
- ...t
17
- } = d, a = S(r, p, u), h = l !== void 0, o = C || y(r, g) || "default", s = B(t), c = [
18
- e.progressBar,
19
- f,
20
- O(t)
21
- ], i = {
22
- width: _(a) * 100 + "%"
8
+ className: m,
9
+ value: o,
10
+ minValue: d = 0,
11
+ maxValue: f = 1,
12
+ color: u,
13
+ ranges: p = {},
14
+ children: r,
15
+ ...l
16
+ } = n, a = x(o, d, f), g = r !== void 0, s = u || P(o, p) || "default", e = y(l), t = ["ProgressBar", m, N(l)], c = {
17
+ width: `${_(a) * 100}%`
23
18
  };
24
- return v.includes(o) || o === "default" ? c.push(e["color__" + o]) : (s.style = { ...s.style, borderColor: o }, i.backgroundColor = o), /* @__PURE__ */ x("div", { className: m(c), ...s, children: [
25
- /* @__PURE__ */ n(
19
+ return C.includes(s) || s === "default" ? t.push(`ProgressBar--color--${s}`) : (e.style = { ...e.style, borderColor: s }, c.backgroundColor = s), /* @__PURE__ */ B("div", { className: v(t), ...e, children: [
20
+ /* @__PURE__ */ i(
26
21
  "div",
27
22
  {
28
- className: m([e.fill, e.fill__animated]),
29
- style: i
23
+ className: "ProgressBar__fill ProgressBar__fill--animated",
24
+ style: c
30
25
  }
31
26
  ),
32
- /* @__PURE__ */ n("div", { className: e.content, children: h ? l : N(a * 100) + "%" })
27
+ /* @__PURE__ */ i("div", { className: "ProgressBar__content", children: g ? r : `${h(a * 100)}%` })
33
28
  ] });
34
29
  }
35
30
  export {
36
- w as ProgressBar
31
+ j as ProgressBar
37
32
  };
@@ -1,89 +1,95 @@
1
1
  import { jsxs as E, jsx as h } from "react/jsx-runtime";
2
- import { KEY_ENTER as I, KEY_ESCAPE as S } from "../common/keycodes.js";
3
- import { clamp as m } from "../common/math.js";
2
+ import { Component as N, createRef as S } from "react";
3
+ import { KEY_ENTER as I, KEY_ESCAPE as b } from "../common/keycodes.js";
4
+ import { clamp as d } from "../common/math.js";
4
5
  import { classes as v } from "../common/react.js";
5
- import { Component as F, createRef as N } from "react";
6
- import { Box as C } from "./Box.js";
6
+ import { Box as F } from "./Box.js";
7
7
  const g = 0, x = 1e4;
8
- function M(e, n, t, s) {
9
- const i = n || g, o = t || t === 0 ? t : x;
10
- let r = s ? e.replace(/[^\-\d.]/g, "") : e.replace(/[^\-\d]/g, "");
11
- return s && (r = b(r, i), r = d(".", r)), n < 0 ? (r = _(r), r = d("-", r)) : r = r.replaceAll("-", ""), i <= 1 && o >= 0 ? V(r, i, o, s) : r;
8
+ function C(s, e, t, n) {
9
+ const i = e || g, o = t || t === 0 ? t : x;
10
+ let r = n ? s.replace(/[^\-\d.]/g, "") : s.replace(/[^\-\d]/g, "");
11
+ return n && (r = V(r, i), r = m(".", r)), e < 0 ? (r = _(r), r = m("-", r)) : r = r.replaceAll("-", ""), i <= 1 && o >= 0 ? M(r, i, o, n) : r;
12
12
  }
13
- const V = (e, n, t, s) => {
14
- let i = s ? parseFloat(e) : parseInt(e, 10);
15
- if (!isNaN(i) && (e.slice(-1) !== "." || i < Math.floor(n))) {
16
- let o = m(i, n, t);
13
+ const M = (s, e, t, n) => {
14
+ const i = n ? Number.parseFloat(s) : Number.parseInt(s, 10);
15
+ if (!Number.isNaN(i) && (s.slice(-1) !== "." || i < Math.floor(e))) {
16
+ const o = d(i, e, t);
17
17
  if (i !== o)
18
18
  return String(o);
19
19
  }
20
- return e;
20
+ return s;
21
21
  };
22
- function _(e) {
23
- let n = e, t = e.indexOf("-");
24
- return t > 0 ? (e = e.replace("-", ""), n = "-".concat(e)) : t === 0 && e.indexOf("-", t + 1) > 0 && (n = e.replaceAll("-", "")), n;
22
+ function _(s) {
23
+ let e = s;
24
+ const t = s.indexOf("-");
25
+ if (t > 0) {
26
+ const n = s.replace("-", "");
27
+ e = "-".concat(n);
28
+ } else t === 0 && s.indexOf("-", t + 1) > 0 && (e = s.replaceAll("-", ""));
29
+ return e;
25
30
  }
26
- function b(e, n) {
27
- let t = e, s = Math.sign(n) * Math.floor(Math.abs(n));
28
- return e.indexOf(".") === 0 ? t = String(s).concat(e) : e.indexOf("-") === 0 && e.indexOf(".") === 1 && (t = s + ".".concat(e.slice(2))), t;
31
+ function V(s, e) {
32
+ let t = s;
33
+ const n = Math.sign(e) * Math.floor(Math.abs(e));
34
+ return s.indexOf(".") === 0 ? t = String(n).concat(s) : s.indexOf("-") === 0 && s.indexOf(".") === 1 && (t = n + ".".concat(s.slice(2))), t;
29
35
  }
30
- function d(e, n) {
31
- const t = n.indexOf(e), s = n.length;
32
- let i = n;
33
- if (t !== -1 && t < s - 1) {
34
- let o = n.slice(t + 1, s);
35
- o = o.replaceAll(e, ""), i = n.slice(0, t + 1).concat(o);
36
+ function m(s, e) {
37
+ const t = e.indexOf(s), n = e.length;
38
+ let i = e;
39
+ if (t !== -1 && t < n - 1) {
40
+ let o = e.slice(t + 1, n);
41
+ o = o.replaceAll(s, ""), i = e.slice(0, t + 1).concat(o);
36
42
  }
37
43
  return i;
38
44
  }
39
- function f(e, n, t, s) {
40
- const i = n || g, o = t || t === 0 ? t : x;
41
- if (!e || !e.length)
45
+ function f(s, e, t, n) {
46
+ const i = e || g, o = t || t === 0 ? t : x;
47
+ if (!s || !s.length)
42
48
  return String(i);
43
- let r = s ? parseFloat(e.replace(/[^\-\d.]/g, "")) : parseInt(e.replace(/[^\-\d]/g, ""), 10);
44
- return isNaN(r) ? String(i) : String(m(r, i, o));
49
+ const r = n ? Number.parseFloat(s.replace(/[^\-\d.]/g, "")) : Number.parseInt(s.replace(/[^\-\d]/g, ""), 10);
50
+ return Number.isNaN(r) ? String(i) : String(d(r, i, o));
45
51
  }
46
- class B extends F {
47
- constructor(n) {
48
- super(n), this.inputRef = N(), this.state = {
52
+ class B extends N {
53
+ constructor(e) {
54
+ super(e), this.inputRef = S(), this.state = {
49
55
  editing: !1
50
56
  }, this.handleBlur = (t) => {
51
- const { maxValue: s, minValue: i, onBlur: o, allowFloats: r } = this.props, { editing: l } = this.state;
57
+ const { maxValue: n, minValue: i, onBlur: o, allowFloats: r } = this.props, { editing: l } = this.state;
52
58
  l && this.setEditing(!1);
53
59
  const a = f(
54
60
  t.target.value,
55
61
  i,
56
- s,
62
+ n,
57
63
  r
58
64
  );
59
65
  o && o(t, +a);
60
66
  }, this.handleChange = (t) => {
61
- const { maxValue: s, minValue: i, onChange: o, allowFloats: r } = this.props;
62
- t.target.value = M(
67
+ const { maxValue: n, minValue: i, onChange: o, allowFloats: r } = this.props;
68
+ t.target.value = C(
63
69
  t.target.value,
64
70
  i,
65
- s,
71
+ n,
66
72
  r
67
73
  ), o && o(t, +t.target.value);
68
74
  }, this.handleFocus = (t) => {
69
- const { editing: s } = this.state;
70
- s || this.setEditing(!0);
75
+ const { editing: n } = this.state;
76
+ n || this.setEditing(!0);
71
77
  }, this.handleInput = (t) => {
72
- const { editing: s } = this.state, { onInput: i } = this.props;
73
- s || this.setEditing(!0), i && i(t, +t.target.value);
78
+ const { editing: n } = this.state, { onInput: i } = this.props;
79
+ n || this.setEditing(!0), i && i(t, +t.target.value);
74
80
  }, this.handleKeyDown = (t) => {
75
- const { maxValue: s, minValue: i, onChange: o, onEnter: r, allowFloats: l } = this.props;
81
+ const { maxValue: n, minValue: i, onChange: o, onEnter: r, allowFloats: l } = this.props;
76
82
  if (t.keyCode === I) {
77
83
  const a = f(
78
84
  t.target.value,
79
85
  i,
80
- s,
86
+ n,
81
87
  l
82
88
  );
83
89
  this.setEditing(!1), o && o(t, +a), r && r(t, +a), t.target.blur();
84
90
  return;
85
91
  }
86
- if (t.keyCode === S) {
92
+ if (t.keyCode === b) {
87
93
  if (this.props.onEscape) {
88
94
  this.props.onEscape(t);
89
95
  return;
@@ -95,41 +101,41 @@ class B extends F {
95
101
  }
96
102
  componentDidMount() {
97
103
  var r;
98
- const { maxValue: n, minValue: t, allowFloats: s } = this.props, i = (r = this.props.value) == null ? void 0 : r.toString(), o = this.inputRef.current;
104
+ const { maxValue: e, minValue: t, allowFloats: n } = this.props, i = (r = this.props.value) == null ? void 0 : r.toString(), o = this.inputRef.current;
99
105
  o && (o.value = f(
100
106
  i,
101
107
  t,
102
- n,
103
- s
108
+ e,
109
+ n
104
110
  )), (this.props.autoFocus || this.props.autoSelect) && setTimeout(() => {
105
111
  o.focus(), this.props.autoSelect && o.select();
106
112
  }, 1);
107
113
  }
108
- componentDidUpdate(n, t) {
109
- var p, c;
110
- const { maxValue: s, minValue: i, allowFloats: o } = this.props, { editing: r } = this.state, l = (p = n.value) == null ? void 0 : p.toString(), a = (c = this.props.value) == null ? void 0 : c.toString(), u = this.inputRef.current;
114
+ componentDidUpdate(e, t) {
115
+ var c, p;
116
+ const { maxValue: n, minValue: i, allowFloats: o } = this.props, { editing: r } = this.state, l = (c = e.value) == null ? void 0 : c.toString(), a = (p = this.props.value) == null ? void 0 : p.toString(), u = this.inputRef.current;
111
117
  u && !r && a !== l && a !== u.value && (u.value = f(
112
118
  a,
113
119
  i,
114
- s,
120
+ n,
115
121
  o
116
122
  ));
117
123
  }
118
- setEditing(n) {
119
- this.setState({ editing: n });
124
+ setEditing(e) {
125
+ this.setState({ editing: e });
120
126
  }
121
127
  render() {
122
- const { props: n } = this, { onChange: t, onEnter: s, onInput: i, onBlur: o, value: r, ...l } = n, { className: a, fluid: u, monospace: p, ...c } = l;
128
+ const { props: e } = this, { onChange: t, onEnter: n, onInput: i, onBlur: o, value: r, ...l } = e, { className: a, fluid: u, monospace: c, ...p } = l;
123
129
  return /* @__PURE__ */ E(
124
- C,
130
+ F,
125
131
  {
126
132
  className: v([
127
133
  "Input",
128
134
  u && "Input--fluid",
129
- p && "Input--monospace",
135
+ c && "Input--monospace",
130
136
  a
131
137
  ]),
132
- ...c,
138
+ ...p,
133
139
  children: [
134
140
  /* @__PURE__ */ h("div", { className: "Input__baseline", children: "." }),
135
141
  /* @__PURE__ */ h(
@@ -1,5 +1,4 @@
1
1
  import { BoxProps } from './Box';
2
-
3
2
  type Props = {
4
3
  /** The current value of the metric. */
5
4
  value: number;