tgui-core 1.1.24 → 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 (117) 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 +2 -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 +58 -52
  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 +60 -0
  45. package/dist/components/ImageButton.js +131 -0
  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 +112 -120
  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 +2 -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 +2 -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/dist/components/index.d.ts +1 -0
  90. package/dist/components/index.js +60 -58
  91. package/package.json +11 -25
  92. package/dist/ProgressBar.module-Jzqlebbx.js +0 -29
  93. package/dist/Section.module-qhQWhlUX.js +0 -18
  94. package/dist/assets/BlockQuote.css +0 -1
  95. package/dist/assets/Button.css +0 -1
  96. package/dist/assets/ColorBox.css +0 -1
  97. package/dist/assets/Dialog.css +0 -1
  98. package/dist/assets/Dimmer.css +0 -1
  99. package/dist/assets/Divider.css +0 -1
  100. package/dist/assets/Flex.css +0 -1
  101. package/dist/assets/Icon.css +0 -6
  102. package/dist/assets/Input.css +0 -1
  103. package/dist/assets/Knob.css +0 -1
  104. package/dist/assets/LabeledList.css +0 -1
  105. package/dist/assets/MenuBar.css +0 -1
  106. package/dist/assets/Modal.css +0 -1
  107. package/dist/assets/NoticeBox.css +0 -1
  108. package/dist/assets/NumberInput.css +0 -1
  109. package/dist/assets/ProgressBar.css +0 -1
  110. package/dist/assets/RoundGauge.css +0 -1
  111. package/dist/assets/Section.css +0 -1
  112. package/dist/assets/Slider.css +0 -1
  113. package/dist/assets/Stack.css +0 -1
  114. package/dist/assets/Table.css +0 -1
  115. package/dist/assets/Tabs.css +0 -1
  116. package/dist/assets/TextArea.css +0 -1
  117. package/dist/assets/Tooltip.css +0 -1
@@ -1,72 +1,70 @@
1
- import { jsx as c } from "react/jsx-runtime";
2
- import { classes as l } from "../common/react.js";
3
- import { computeBoxClassName as m, computeBoxProps as a, unit as d } from "./Box.js";
4
- import '../assets/Flex.css';const p = "_flex_djoni_5", N = "_inline_djoni_10", r = {
5
- flex: p,
6
- inline: N
7
- };
8
- function y(e) {
9
- return l([
10
- r.flex,
11
- e.inline && r.inline,
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ import { classes as r } from "../common/react.js";
3
+ import { computeBoxClassName as m, computeBoxProps as a, unit as f } from "./Box.js";
4
+ function p(e) {
5
+ return r([
6
+ "Flex",
7
+ e.inline && "Flex--inline",
12
8
  m(e)
13
9
  ]);
14
10
  }
15
- function v(e) {
16
- const { direction: n, wrap: t, align: o, justify: s, ...i } = e;
11
+ function d(e) {
12
+ const { direction: s, wrap: t, align: i, justify: n, ...o } = e;
17
13
  return a({
18
14
  style: {
19
- ...i.style,
20
- flexDirection: n,
15
+ ...o.style,
16
+ flexDirection: s,
21
17
  flexWrap: t === !0 ? "wrap" : t,
22
- alignItems: o,
23
- justifyContent: s
18
+ alignItems: i,
19
+ justifyContent: n
24
20
  },
25
- ...i
21
+ ...o
26
22
  });
27
23
  }
28
- function _(e) {
29
- const { className: n, ...t } = e;
30
- return /* @__PURE__ */ c(
24
+ function F(e) {
25
+ const { className: s, ...t } = e;
26
+ return /* @__PURE__ */ l(
31
27
  "div",
32
28
  {
33
- className: l([n, y(t)]),
34
- ...v(t)
29
+ className: r([s, p(t)]),
30
+ ...d(t)
35
31
  }
36
32
  );
37
33
  }
38
- function g(e) {
39
- const { style: n, grow: t, order: o, shrink: s, basis: i, align: u, ...f } = e, x = i ?? // IE11: Set basis to specified width if it's known, which fixes certain
34
+ const N = (e) => r(["Flex__item", m(e)]);
35
+ function v(e) {
36
+ const { style: s, grow: t, order: i, shrink: n, basis: o, align: c, ...u } = e, x = o ?? // IE11: Set basis to specified width if it's known, which fixes certain
40
37
  // bugs when rendering tables inside the flex.
41
38
  e.width ?? // If grow is used, basis should be set to 0 to be consistent with
42
39
  // flex css shorthand `flex: 1`.
43
40
  (t !== void 0 ? 0 : void 0);
44
41
  return a({
45
42
  style: {
46
- ...n,
43
+ ...s,
47
44
  flexGrow: t !== void 0 && Number(t),
48
- flexShrink: s !== void 0 && Number(s),
49
- flexBasis: d(x),
50
- order: o,
51
- alignSelf: u
45
+ flexShrink: n !== void 0 && Number(n),
46
+ flexBasis: f(x),
47
+ order: i,
48
+ alignSelf: c
52
49
  },
53
- ...f
50
+ ...u
54
51
  });
55
52
  }
56
- function j(e) {
57
- const { className: n, ...t } = e;
58
- return /* @__PURE__ */ c(
53
+ function y(e) {
54
+ const { className: s, ...t } = e;
55
+ return /* @__PURE__ */ l(
59
56
  "div",
60
57
  {
61
- className: l([n, m(e)]),
62
- ...g(t)
58
+ className: r([s, N(e)]),
59
+ ...v(t)
63
60
  }
64
61
  );
65
62
  }
66
- _.Item = j;
63
+ F.Item = y;
67
64
  export {
68
- _ as Flex,
69
- y as computeFlexClassName,
70
- g as computeFlexItemProps,
71
- v as computeFlexProps
65
+ F as Flex,
66
+ p as computeFlexClassName,
67
+ N as computeFlexItemClassName,
68
+ v as computeFlexItemProps,
69
+ d as computeFlexProps
72
70
  };
@@ -1,7 +1,6 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { BooleanLike } from '../common/react';
3
3
  import { BoxProps } from './Box';
4
-
5
4
  type Props = {
6
5
  /** Icon name. See [icon list](https://fontawesome.com/v5/search?o=r&m=free) */
7
6
  name: string;
@@ -1,51 +1,44 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import { classes as m } from "../common/react.js";
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { classes as l } from "../common/react.js";
3
3
  import { computeBoxProps as p, computeBoxClassName as u } from "./Box.js";
4
- import '../assets/Icon.css';const x = "_iconStack_bg05l_7", y = "_icon_bg05l_7", S = {
5
- iconStack: x,
6
- icon: y
7
- }, f = /-o$/;
8
- function b(a) {
9
- const { name: t, size: o, spin: c, className: _, rotation: i, ...n } = a, e = n.style || {};
10
- o && (e.fontSize = o * 100 + "%"), i && (e.transform = `rotate(${i}deg)`), n.style = e;
11
- const N = p(n);
12
- let s = "";
13
- if (t.startsWith("tg-"))
14
- s = t;
4
+ const f = /-o$/;
5
+ function d(c) {
6
+ const { name: s, size: o, spin: a, className: N, rotation: r, ...e } = c, n = e.style || {};
7
+ o && (n.fontSize = `${o * 100}%`), r && (n.transform = `rotate(${r}deg)`), e.style = n;
8
+ const x = p(e);
9
+ let t = "";
10
+ if (s.startsWith("tg-"))
11
+ t = s;
15
12
  else {
16
- const k = f.test(t), r = t.replace(f, ""), g = !r.startsWith("fa-");
17
- s = k ? "far " : "fas ", g && (s += "fa-"), s += r, c && (s += " fa-spin");
13
+ const I = f.test(s), i = s.replace(f, ""), S = !i.startsWith("fa-");
14
+ t = I ? "far " : "fas ", S && (t += "fa-"), t += i, a && (t += " fa-spin");
18
15
  }
19
- return /* @__PURE__ */ l(
16
+ return /* @__PURE__ */ m(
20
17
  "i",
21
18
  {
22
- className: m([
23
- S.icon,
24
- s,
25
- _,
26
- u(n)
19
+ className: l([
20
+ "Icon",
21
+ t,
22
+ N,
23
+ u(e)
27
24
  ]),
28
- ...N
25
+ ...x
29
26
  }
30
27
  );
31
28
  }
32
- function d(a) {
33
- const { className: t, children: o, ...c } = a;
34
- return /* @__PURE__ */ l(
29
+ function g(c) {
30
+ const { className: s, children: o, ...a } = c;
31
+ return /* @__PURE__ */ m(
35
32
  "span",
36
33
  {
37
- className: m([
38
- S.iconStack,
39
- t,
40
- u(c)
41
- ]),
42
- ...p(c),
34
+ className: l(["IconStack", s, u(a)]),
35
+ ...p(a),
43
36
  children: o
44
37
  }
45
38
  );
46
39
  }
47
- b.Stack = d;
40
+ d.Stack = g;
48
41
  export {
49
- b as Icon,
50
- d as IconStack
42
+ d as Icon,
43
+ g as IconStack
51
44
  };
@@ -1,5 +1,4 @@
1
1
  import { BoxProps } from './Box';
2
-
3
2
  type Props = Partial<{
4
3
  className: string;
5
4
  /** True is default, this fixes an ie thing */
@@ -1,15 +1,15 @@
1
1
  import { jsx as p } from "react/jsx-runtime";
2
- import { useRef as f } from "react";
3
- import { computeBoxProps as a } from "./Box.js";
2
+ import { useRef as a } from "react";
3
+ import { computeBoxProps as f } from "./Box.js";
4
4
  const l = 5;
5
- function b(o) {
5
+ function E(o) {
6
6
  const {
7
7
  fixBlur: s = !0,
8
8
  fixErrors: m = !1,
9
9
  objectFit: n = "fill",
10
10
  src: e,
11
11
  ...c
12
- } = o, t = f(0), r = a(c);
12
+ } = o, t = a(0), r = f(c);
13
13
  return r.style = {
14
14
  ...r.style,
15
15
  "-ms-interpolation-mode": s ? "nearest-neighbor" : "auto",
@@ -26,10 +26,11 @@ function b(o) {
26
26
  }
27
27
  },
28
28
  src: e,
29
- ...r
29
+ ...r,
30
+ alt: "dm icon"
30
31
  }
31
32
  );
32
33
  }
33
34
  export {
34
- b as Image
35
+ E as Image
35
36
  };
@@ -0,0 +1,60 @@
1
+ import { Placement } from '@popperjs/core';
2
+ import { ReactNode } from 'react';
3
+ import { BooleanLike } from '../common/react';
4
+ import { BoxProps } from './Box';
5
+ type Props = Partial<{
6
+ /** Asset cache. Example: `asset={['assetname32x32', thing.key]}` */
7
+ asset: string[];
8
+ /** Classic way to put images. Example: `base64={thing.image}` */
9
+ base64: string;
10
+ /**
11
+ * Special container for buttons.
12
+ * You can put any other component here.
13
+ * Has some special stylings!
14
+ * Example: `buttons={<Button>Send</Button>}`
15
+ */
16
+ buttons: ReactNode;
17
+ /**
18
+ * Enables alternate layout for `buttons` container.
19
+ * Without fluid, buttons will be on top and with `pointer-events: none`, useful for text info.
20
+ * With fluid, buttons will be in "hamburger" style.
21
+ */
22
+ buttonsAlt: boolean;
23
+ /** Content under image. Or on the right if fluid. */
24
+ children: ReactNode;
25
+ /** Applies a CSS class to the element. */
26
+ className: string;
27
+ /** Color of the button. See [Button](#button) but without `transparent`. */
28
+ color: string;
29
+ /** Makes button disabled and dark red if true. Also disables onClick. */
30
+ disabled: BooleanLike;
31
+ /** Optional. Adds a "stub" when loading DmIcon. */
32
+ dmFallback: ReactNode;
33
+ /** Parameter `icon` of component `DmIcon`. */
34
+ dmIcon: string | null;
35
+ /** Parameter `icon_state` of component `DmIcon`. */
36
+ dmIconState: string | null;
37
+ /**
38
+ * Changes the layout of the button, making it fill the entire horizontally available space.
39
+ * Allows the use of `title`
40
+ */
41
+ fluid: boolean;
42
+ /** Parameter responsible for the size of the image, component and standard "stubs". */
43
+ imageSize: number;
44
+ /** Prop `src` of Image component. Example: `imageSrc={resolveAsset(thing.image}` */
45
+ imageSrc: string;
46
+ /** Called when button is clicked with LMB. */
47
+ onClick: (e: any) => void;
48
+ /** Called when button is clicked with RMB. */
49
+ onRightClick: (e: any) => void;
50
+ /** Makes button selected and green if true. */
51
+ selected: BooleanLike;
52
+ /** Requires `fluid` for work. Bold text with divider betwen content. */
53
+ title: string;
54
+ /** A fancy, boxy tooltip, which appears when hovering over the button */
55
+ tooltip: ReactNode;
56
+ /** Position of the tooltip. See [`Popper`](#Popper) for valid options. */
57
+ tooltipPosition: Placement;
58
+ }> & BoxProps;
59
+ export declare function ImageButton(props: Props): import("react/jsx-runtime").JSX.Element;
60
+ export {};
@@ -0,0 +1,131 @@
1
+ import { jsxs as f, jsx as t } from "react/jsx-runtime";
2
+ import { classes as l } from "../common/react.js";
3
+ import { computeBoxProps as B } from "./Box.js";
4
+ import { DmIcon as D } from "./DmIcon.js";
5
+ import { Icon as F } from "./Icon.js";
6
+ import { Image as j } from "./Image.js";
7
+ import { Stack as I } from "./Stack.js";
8
+ import { Tooltip as z } from "./Tooltip.js";
9
+ function H(k) {
10
+ const {
11
+ asset: h,
12
+ base64: r,
13
+ buttons: m,
14
+ buttonsAlt: g,
15
+ children: i,
16
+ className: w,
17
+ color: e,
18
+ disabled: a,
19
+ dmFallback: b,
20
+ dmIcon: x,
21
+ dmIconState: C,
22
+ fluid: c,
23
+ imageSize: o = 64,
24
+ imageSrc: d,
25
+ onClick: s,
26
+ onRightClick: p,
27
+ selected: _,
28
+ title: $,
29
+ tooltip: y,
30
+ tooltipPosition: v,
31
+ ...S
32
+ } = k;
33
+ function N(n, A) {
34
+ return /* @__PURE__ */ t(I, { height: `${o}px`, width: `${o}px`, children: /* @__PURE__ */ t(I.Item, { grow: !0, textAlign: "center", align: "center", children: /* @__PURE__ */ t(
35
+ F,
36
+ {
37
+ spin: A,
38
+ name: n,
39
+ color: "gray",
40
+ style: { fontSize: `calc(${o}px * 0.75)` }
41
+ }
42
+ ) }) });
43
+ }
44
+ let u = /* @__PURE__ */ f(
45
+ "div",
46
+ {
47
+ className: l([
48
+ "container",
49
+ m && "hasButtons",
50
+ !s && !p && "noAction",
51
+ _ && "selected",
52
+ a && "disabled",
53
+ e && typeof e == "string" ? `color__${e}` : "color__default"
54
+ ]),
55
+ tabIndex: a ? void 0 : 0,
56
+ onClick: (n) => {
57
+ !a && s && s(n);
58
+ },
59
+ onKeyDown: (n) => {
60
+ n.key === "Enter" && !a && s && s(n);
61
+ },
62
+ onContextMenu: (n) => {
63
+ n.preventDefault(), !a && p && p(n);
64
+ },
65
+ style: { width: c ? "auto" : `calc(${o}px + 0.5em + 2px)` },
66
+ children: [
67
+ /* @__PURE__ */ t("div", { className: "image", children: r || h || d ? /* @__PURE__ */ t(
68
+ j,
69
+ {
70
+ className: l(!r && !d && h || []),
71
+ src: r ? `data:image/png;base64,${r}` : d,
72
+ height: `${o}px`,
73
+ width: `${o}px`
74
+ }
75
+ ) : x && C ? /* @__PURE__ */ t(
76
+ D,
77
+ {
78
+ icon: x,
79
+ icon_state: C,
80
+ fallback: b || N("spinner", !0),
81
+ height: `${o}px`,
82
+ width: `${o}px`
83
+ }
84
+ ) : N("question", !1) }),
85
+ c ? /* @__PURE__ */ f("div", { className: "info", children: [
86
+ $ && /* @__PURE__ */ t("span", { className: l(["title", i && "divider"]), children: $ }),
87
+ i && /* @__PURE__ */ t("span", { className: "contentFluid", children: i })
88
+ ] }) : i && /* @__PURE__ */ t(
89
+ "span",
90
+ {
91
+ className: l([
92
+ "content",
93
+ _ && "contentSelected",
94
+ a && "contentDisabled",
95
+ e && typeof e == "string" ? `contentColor__${e}` : "contentColor__default"
96
+ ]),
97
+ children: i
98
+ }
99
+ )
100
+ ]
101
+ }
102
+ );
103
+ return y && (u = /* @__PURE__ */ t(z, { content: y, position: v, children: u })), /* @__PURE__ */ f(
104
+ "div",
105
+ {
106
+ className: l(["ImageButton", c && "fluid", w]),
107
+ ...B(S),
108
+ children: [
109
+ u,
110
+ m && /* @__PURE__ */ t(
111
+ "div",
112
+ {
113
+ className: l([
114
+ "buttonsContainer",
115
+ g && "buttonsAltContainer",
116
+ !i && "buttonsEmpty",
117
+ c && e && typeof e == "string" ? `buttonsContainerColor__${e}` : c && "buttonsContainerColor__default"
118
+ ]),
119
+ style: {
120
+ width: g ? `calc(${o}px + 0.5em)` : "auto"
121
+ },
122
+ children: m
123
+ }
124
+ )
125
+ ]
126
+ }
127
+ );
128
+ }
129
+ export {
130
+ H as ImageButton
131
+ };
@@ -24,7 +24,7 @@ class k extends v {
24
24
  }
25
25
  doOffsetMouse(e) {
26
26
  const { zoom: o } = this.state;
27
- e.screenZoomX = e.screenX * Math.pow(o, -1), e.screenZoomY = e.screenY * Math.pow(o, -1);
27
+ e.screenZoomX = e.screenX * o ** -1, e.screenZoomY = e.screenY * o ** -1;
28
28
  }
29
29
  handleMouseDown(e) {
30
30
  this.setState((o) => ({
@@ -1,6 +1,5 @@
1
1
  import { SyntheticEvent } from 'react';
2
2
  import { BoxProps } from './Box';
3
-
4
3
  type ConditionalProps = {
5
4
  /**
6
5
  * Mark this if you want to debounce onInput.
@@ -1,88 +1,81 @@
1
- import { jsxs as K, jsx as m } from "react/jsx-runtime";
2
- import { useRef as V, useEffect as d } from "react";
3
- import { KEY as j, isEscape as k } from "../common/keys.js";
4
- import { classes as B } from "../common/react.js";
5
- import { debounce as R } from "../common/timer.js";
6
- import { Box as S } from "./Box.js";
7
- import '../assets/Input.css';const F = "_input_17i79_20", L = "_fluid_17i79_35", Y = "_baseline_17i79_40", q = "_inner_17i79_45", v = "_monospace_17i79_71", u = {
8
- input: F,
9
- fluid: L,
10
- baseline: Y,
11
- inner: q,
12
- monospace: v
13
- };
14
- function a(r) {
15
- return typeof r != "number" && typeof r != "string" ? "" : String(r);
1
+ import { jsxs as E, jsx as p } from "react/jsx-runtime";
2
+ import { useRef as K, useEffect as m } from "react";
3
+ import { KEY as V, isEscape as j } from "../common/keys.js";
4
+ import { classes as k } from "../common/react.js";
5
+ import { debounce as B } from "../common/timer.js";
6
+ import { Box as R } from "./Box.js";
7
+ function l(u) {
8
+ return typeof u != "number" && typeof u != "string" ? "" : String(u);
16
9
  }
17
- const z = R((r) => r(), 250);
18
- function P(r) {
10
+ const S = B((u) => u(), 250);
11
+ function A(u) {
19
12
  const {
20
- autoFocus: _,
21
- autoSelect: f,
22
- className: b,
23
- disabled: g,
13
+ autoFocus: d,
14
+ autoSelect: s,
15
+ className: g,
16
+ disabled: I,
24
17
  expensive: T,
25
- fluid: y,
18
+ fluid: b,
26
19
  maxLength: x,
27
- monospace: h,
20
+ monospace: y,
28
21
  onChange: t,
29
- onEnter: i,
22
+ onEnter: n,
30
23
  onEscape: o,
31
- onInput: s,
32
- placeholder: w,
33
- selfClear: I,
34
- value: c,
24
+ onInput: i,
25
+ placeholder: h,
26
+ selfClear: w,
27
+ value: a,
35
28
  ...N
36
- } = r, l = V(null);
37
- function D(e) {
38
- var p;
39
- if (!s) return;
40
- const n = (p = e.currentTarget) == null ? void 0 : p.value;
41
- T ? z(() => s(e, n)) : s(e, n);
29
+ } = u, c = K(null);
30
+ function _(e) {
31
+ var f;
32
+ if (!i) return;
33
+ const r = (f = e.currentTarget) == null ? void 0 : f.value;
34
+ T ? S(() => i(e, r)) : i(e, r);
42
35
  }
43
- function E(e) {
44
- if (e.key === j.Enter) {
45
- i == null || i(e, e.currentTarget.value), I ? e.currentTarget.value = "" : (e.currentTarget.blur(), t == null || t(e, e.currentTarget.value));
36
+ function D(e) {
37
+ if (e.key === V.Enter) {
38
+ n == null || n(e, e.currentTarget.value), w ? e.currentTarget.value = "" : (e.currentTarget.blur(), t == null || t(e, e.currentTarget.value));
46
39
  return;
47
40
  }
48
- k(e.key) && (o == null || o(e), e.currentTarget.value = a(c), e.currentTarget.blur());
41
+ j(e.key) && (o == null || o(e), e.currentTarget.value = l(a), e.currentTarget.blur());
49
42
  }
50
- return d(() => {
51
- const e = l.current;
43
+ return m(() => {
44
+ const e = c.current;
52
45
  if (!e) return;
53
- const n = a(c);
54
- e.value !== n && (e.value = n), !(!_ && !f) && setTimeout(() => {
55
- e.focus(), f && e.select();
46
+ const r = l(a);
47
+ e.value !== r && (e.value = r), !(!d && !s) && setTimeout(() => {
48
+ e.focus(), s && e.select();
56
49
  }, 1);
57
- }, []), d(() => {
58
- const e = l.current;
50
+ }, []), m(() => {
51
+ const e = c.current;
59
52
  if (!e || document.activeElement === e)
60
53
  return;
61
- const n = a(c);
62
- e.value !== n && (e.value = n);
63
- }), /* @__PURE__ */ K(
64
- S,
54
+ const r = l(a);
55
+ e.value !== r && (e.value = r);
56
+ }), /* @__PURE__ */ E(
57
+ R,
65
58
  {
66
- className: B([
67
- u.input,
68
- y && u.fluid,
69
- h && u.monospace,
70
- b
59
+ className: k([
60
+ "Input",
61
+ b && "Input--fluid",
62
+ y && "Input--monospace",
63
+ g
71
64
  ]),
72
65
  ...N,
73
66
  children: [
74
- /* @__PURE__ */ m("div", { className: u.baseline, children: "." }),
75
- /* @__PURE__ */ m(
67
+ /* @__PURE__ */ p("div", { className: "Input__baseline", children: "." }),
68
+ /* @__PURE__ */ p(
76
69
  "input",
77
70
  {
78
- className: u.inner,
79
- disabled: g,
71
+ className: "Input__input",
72
+ disabled: I,
80
73
  maxLength: x,
81
74
  onBlur: (e) => t == null ? void 0 : t(e, e.target.value),
82
- onChange: D,
83
- onKeyDown: E,
84
- placeholder: w,
85
- ref: l
75
+ onChange: _,
76
+ onKeyDown: D,
77
+ placeholder: h,
78
+ ref: c
86
79
  }
87
80
  )
88
81
  ]
@@ -90,6 +83,6 @@ function P(r) {
90
83
  );
91
84
  }
92
85
  export {
93
- P as Input,
94
- a as toInputValue
86
+ A as Input,
87
+ l as toInputValue
95
88
  };
@@ -1,6 +1,5 @@
1
1
  import { Component } from 'react';
2
2
  import { KeyEvent } from '../common/events';
3
-
4
3
  type KeyListenerProps = Partial<{
5
4
  onKey: (key: KeyEvent) => void;
6
5
  onKeyDown: (key: KeyEvent) => void;
@@ -1,6 +1,5 @@
1
1
  import { BooleanLike } from '../common/react';
2
2
  import { BoxProps } from './Box';
3
-
4
3
  type Props = {
5
4
  /** Value itself, controls the position of the cursor. */
6
5
  value: number;