tgui-core 1.7.4 → 1.7.6

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.
@@ -1,10 +1,10 @@
1
1
  type Zip<T extends unknown[][]> = {
2
- [I in keyof T]: T[I] extends (infer U)[] ? U : never;
2
+ [K in keyof T]: T[K] extends (infer U)[] ? U : never;
3
3
  }[];
4
4
  /**
5
5
  * Creates an array of grouped elements, the first of which contains
6
6
  * the first elements of the given arrays, the second of which contains
7
7
  * the second elements of the given arrays, and so on.
8
8
  */
9
- export declare function zip<T extends unknown[][]>(...arrays: T): Zip<T>;
9
+ export declare function zip<T extends unknown[][]>(...arr: T): Zip<T>;
10
10
  export {};
@@ -1,15 +1,6 @@
1
- function s(...n) {
2
- if (n.length === 0)
3
- return [];
4
- const o = n.length, r = n[0].length, u = [];
5
- for (let t = 0; t < r; t++) {
6
- const l = [];
7
- for (let e = 0; e < o; e++)
8
- l.push(n[e][t]);
9
- u.push(l);
10
- }
11
- return u;
1
+ function m(...a) {
2
+ return Array(Math.max(...a.map((p) => p.length))).fill(void 0).map((p, t) => a.map((i) => i[t]));
12
3
  }
13
4
  export {
14
- s as zip
5
+ m as zip
15
6
  };
@@ -21,11 +21,14 @@
21
21
  *
22
22
  */
23
23
  export declare enum KEY {
24
+ A = "a",
24
25
  Alt = "Alt",
25
26
  Backspace = "Backspace",
26
27
  Control = "Control",
28
+ D = "d",
27
29
  Delete = "Delete",
28
30
  Down = "ArrowDown",
31
+ E = "e",
29
32
  End = "End",
30
33
  Enter = "Enter",
31
34
  Esc = "Esc",
@@ -33,13 +36,17 @@ export declare enum KEY {
33
36
  Home = "Home",
34
37
  Insert = "Insert",
35
38
  Left = "ArrowLeft",
39
+ N = "n",
36
40
  PageDown = "PageDown",
37
41
  PageUp = "PageUp",
38
42
  Right = "ArrowRight",
43
+ S = "s",
39
44
  Shift = "Shift",
40
45
  Space = " ",
41
46
  Tab = "Tab",
42
- Up = "ArrowUp"
47
+ Up = "ArrowUp",
48
+ W = "w",
49
+ Z = "z"
43
50
  }
44
51
  /**
45
52
  * ### isEscape
@@ -53,3 +60,57 @@ export declare enum KEY {
53
60
  * @returns true if key is Escape or Esc, false otherwise
54
61
  */
55
62
  export declare function isEscape(key: string): boolean;
63
+ /**
64
+ * ### isAlphabetic
65
+ *
66
+ * Checks if the user has hit any alphabetic key (a - z)
67
+ *
68
+ * @param key - the key to check, typically from event.key
69
+ * @returns true if key is in the range of a-z
70
+ */
71
+ export declare function isAlphabetic(key: string): boolean;
72
+ /**
73
+ * ### isNumeric
74
+ *
75
+ * Checks if the user has hit any numeric key (0 - 9)
76
+ *
77
+ * @param key - the key to check, typically from event.key
78
+ * @returns true if key is in the range of 0 - 9
79
+ */
80
+ export declare function isNumeric(key: string): boolean;
81
+ /**
82
+ * ### isCardinal
83
+ *
84
+ * Checks if the user has hit any cardinal key (n s w e)
85
+ *
86
+ * @param key - the key to check, typically from event.key
87
+ * @returns true if key matches any cardinal n s w e
88
+ */
89
+ export declare function isCardinal(key: string): boolean;
90
+ /**
91
+ * ### isArrow
92
+ *
93
+ * Checks if the user has hit any arrow key
94
+ *
95
+ * @param key - the key to check, typically from event.key
96
+ * @returns true if key matches any arrow keys
97
+ */
98
+ export declare function isArrow(key: string): boolean;
99
+ /**
100
+ * ### isWasd
101
+ *
102
+ * Checks if the user has hit any w a s d key
103
+ *
104
+ * @param key - the key to check, typically from event.key
105
+ * @returns true if key matches any w a s d
106
+ */
107
+ export declare function isWasd(key: string): boolean;
108
+ /**
109
+ * ### isMovement
110
+ *
111
+ * Checks if the user has hit any movement key (w a s d and arrow keys)
112
+ *
113
+ * @param key - the key to check, typically from event.key
114
+ * @returns true if key matches any movement key w a s d and arrow keys
115
+ */
116
+ export declare function isMovement(key: string): boolean;
@@ -1,8 +1,32 @@
1
- var r = /* @__PURE__ */ ((e) => (e.Alt = "Alt", e.Backspace = "Backspace", e.Control = "Control", e.Delete = "Delete", e.Down = "ArrowDown", e.End = "End", e.Enter = "Enter", e.Esc = "Esc", e.Escape = "Escape", e.Home = "Home", e.Insert = "Insert", e.Left = "ArrowLeft", e.PageDown = "PageDown", e.PageUp = "PageUp", e.Right = "ArrowRight", e.Shift = "Shift", e.Space = " ", e.Tab = "Tab", e.Up = "ArrowUp", e))(r || {});
2
- function t(e) {
3
- return e === "Esc" || e === "Escape";
1
+ var n = /* @__PURE__ */ ((r) => (r.A = "a", r.Alt = "Alt", r.Backspace = "Backspace", r.Control = "Control", r.D = "d", r.Delete = "Delete", r.Down = "ArrowDown", r.E = "e", r.End = "End", r.Enter = "Enter", r.Esc = "Esc", r.Escape = "Escape", r.Home = "Home", r.Insert = "Insert", r.Left = "ArrowLeft", r.N = "n", r.PageDown = "PageDown", r.PageUp = "PageUp", r.Right = "ArrowRight", r.S = "s", r.Shift = "Shift", r.Space = " ", r.Tab = "Tab", r.Up = "ArrowUp", r.W = "w", r.Z = "z", r))(n || {});
2
+ function e(r) {
3
+ return r === "Esc" || r === "Escape";
4
+ }
5
+ function a(r) {
6
+ return r >= "a" && r <= "z";
7
+ }
8
+ function i(r) {
9
+ return r >= "0" && r <= "9";
10
+ }
11
+ function s(r) {
12
+ return r === "n" || r === "s" || r === "w" || r === "e";
13
+ }
14
+ function t(r) {
15
+ return r === "ArrowUp" || r === "ArrowDown" || r === "ArrowLeft" || r === "ArrowRight";
16
+ }
17
+ function o(r) {
18
+ return r === "w" || r === "a" || r === "s" || r === "d";
19
+ }
20
+ function c(r) {
21
+ return o(r) || t(r);
4
22
  }
5
23
  export {
6
- r as KEY,
7
- t as isEscape
24
+ n as KEY,
25
+ a as isAlphabetic,
26
+ t as isArrow,
27
+ s as isCardinal,
28
+ e as isEscape,
29
+ c as isMovement,
30
+ i as isNumeric,
31
+ o as isWasd
8
32
  };
@@ -1,4 +1,4 @@
1
- function p(e, t = (r) => JSON.stringify(r)) {
1
+ function l(e, t = (r) => JSON.stringify(r)) {
2
2
  const r = e.toLowerCase().trim();
3
3
  return (n) => {
4
4
  if (!r)
@@ -8,16 +8,16 @@ function p(e, t = (r) => JSON.stringify(r)) {
8
8
  };
9
9
  }
10
10
  const a = ["a", "e", "i", "o", "u"];
11
- function l(e, t, r) {
11
+ function f(e, t, r) {
12
12
  return t === 1 ? e : r ? e + r : e.endsWith("s") || e.endsWith("x") || e.endsWith("z") || e.endsWith("ch") || e.endsWith("sh") ? `${e}es` : e.endsWith("y") && !a.includes(e.charAt(e.length - 2)) ? `${e.slice(0, -1)}ies` : `${e}s`;
13
13
  }
14
14
  function c(e) {
15
15
  return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
16
16
  }
17
- function f(e) {
17
+ function h(e) {
18
18
  return e.replace(/(^\w{1})|(\s+\w{1})/g, (t) => t.toUpperCase());
19
19
  }
20
- function h(e) {
20
+ function g(e) {
21
21
  return e.replace(/^\w/, (t) => t.toUpperCase());
22
22
  }
23
23
  const i = ["Id", "Tv"], u = [
@@ -43,7 +43,7 @@ const i = ["Id", "Tv"], u = [
43
43
  "To",
44
44
  "With"
45
45
  ];
46
- function g(e) {
46
+ function d(e) {
47
47
  if (!e) return e;
48
48
  let t = e.replace(/([^\W_]+[^\s-]*) */g, (r) => c(r));
49
49
  for (const r of u) {
@@ -56,20 +56,19 @@ function g(e) {
56
56
  }
57
57
  return t;
58
58
  }
59
- const s = {
59
+ const s = /&(nbsp|amp|quot|lt|gt|apos|trade|copy);/g, p = {
60
60
  amp: "&",
61
61
  apos: "'",
62
62
  gt: ">",
63
63
  lt: "<",
64
64
  nbsp: " ",
65
- quot: '"'
65
+ quot: '"',
66
+ trade: "™",
67
+ cops: "©"
66
68
  };
67
- function d(e) {
69
+ function m(e) {
68
70
  return e && e.replace(/<br>/gi, `
69
- `).replace(/<\/?[a-z0-9-_]+[^>]*>/gi, "").replace(
70
- /&(nbsp|amp|quot|lt|gt|apos);/g,
71
- (t, r) => s[r]
72
- ).replace(/&#?([0-9]+);/gi, (t, r) => {
71
+ `).replace(/<\/?[a-z0-9-_]+[^>]*>/gi, "").replace(s, (t, r) => p[r]).replace(/&#?([0-9]+);/gi, (t, r) => {
73
72
  const n = Number.parseInt(r, 10);
74
73
  return String.fromCharCode(n);
75
74
  }).replace(/&#x?([0-9a-f]+);/gi, (t, r) => {
@@ -80,10 +79,10 @@ function d(e) {
80
79
  export {
81
80
  a as VOWELS,
82
81
  c as capitalize,
83
- f as capitalizeAll,
84
- h as capitalizeFirst,
85
- p as createSearch,
86
- d as decodeHtmlEntities,
87
- l as pluralize,
88
- g as toTitleCase
82
+ h as capitalizeAll,
83
+ g as capitalizeFirst,
84
+ l as createSearch,
85
+ m as decodeHtmlEntities,
86
+ f as pluralize,
87
+ d as toTitleCase
89
88
  };
@@ -0,0 +1,18 @@
1
+ /** Represents a vector as an array of numbers */
2
+ export type Vector = number[];
3
+ /** Adds multiple vectors together element-wise */
4
+ export declare function vecAdd(...vecs: Vector[]): Vector;
5
+ /** Subtracts multiple vectors element-wise */
6
+ export declare function vecSubtract(...vecs: Vector[]): Vector;
7
+ /** Multiplies multiple vectors element-wise */
8
+ export declare function vecMultiply(...vecs: Vector[]): Vector;
9
+ /** Divides multiple vectors element-wise */
10
+ export declare function vecDivide(...vecs: Vector[]): Vector;
11
+ /** Multiplies a vector by a scalar number */
12
+ export declare function vecScale(vec: Vector, n: number): Vector;
13
+ /** Negates all elements of a vector */
14
+ export declare function vecInverse(vec: Vector): Vector;
15
+ /** Calculates the Euclidean length of a vector */
16
+ export declare function vecLength(vec: Vector): number;
17
+ /** Returns a normalized (unit length) version of the vector */
18
+ export declare function vecNormalize(vec: Vector): Vector;
@@ -0,0 +1,48 @@
1
+ import { zip as r } from "./collections.js";
2
+ function u(n, e) {
3
+ return n + e;
4
+ }
5
+ function c(n, e) {
6
+ return n - e;
7
+ }
8
+ function i(n, e) {
9
+ return n * e;
10
+ }
11
+ function o(n, e) {
12
+ return n / e;
13
+ }
14
+ function m(...n) {
15
+ return r(...n).map((e) => e.reduce(u));
16
+ }
17
+ function p(...n) {
18
+ return r(...n).map((e) => e.reduce(c));
19
+ }
20
+ function f(...n) {
21
+ return r(...n).map((e) => e.reduce(i));
22
+ }
23
+ function v(...n) {
24
+ return r(...n).map((e) => e.reduce(o));
25
+ }
26
+ function l(n, e) {
27
+ return n.map((t) => t * e);
28
+ }
29
+ function s(n) {
30
+ return n.map((e) => -e);
31
+ }
32
+ function a(n) {
33
+ return Math.sqrt(f(n, n).reduce(u));
34
+ }
35
+ function h(n) {
36
+ const e = a(n);
37
+ return n.map((t) => t / e);
38
+ }
39
+ export {
40
+ m as vecAdd,
41
+ v as vecDivide,
42
+ s as vecInverse,
43
+ a as vecLength,
44
+ f as vecMultiply,
45
+ h as vecNormalize,
46
+ l as vecScale,
47
+ p as vecSubtract
48
+ };
@@ -16,9 +16,9 @@ function N(o) {
16
16
  compact: h,
17
17
  content: B,
18
18
  disabled: t,
19
- ellipsis: c,
19
+ ellipsis: i,
20
20
  fluid: e,
21
- icon: i,
21
+ icon: c,
22
22
  iconColor: a,
23
23
  iconPosition: C,
24
24
  iconRotation: I,
@@ -26,10 +26,10 @@ function N(o) {
26
26
  iconSpin: P,
27
27
  onClick: f,
28
28
  selected: x,
29
- tooltip: g,
29
+ tooltip: b,
30
30
  tooltipPosition: w,
31
31
  verticalAlignContent: y,
32
- ...b
32
+ ...g
33
33
  } = o, n = B || u;
34
34
  let k = /* @__PURE__ */ r(
35
35
  "div",
@@ -47,7 +47,7 @@ function N(o) {
47
47
  y && `Button--verticalAlignContent--${y}`,
48
48
  l && typeof l == "string" ? `Button--color--${l}` : "Button--color--default",
49
49
  d,
50
- j(b)
50
+ j(g)
51
51
  ]),
52
52
  tabIndex: t ? void 0 : 0,
53
53
  onClick: (p) => {
@@ -62,44 +62,44 @@ function N(o) {
62
62
  E(p.key) && p.preventDefault();
63
63
  }
64
64
  },
65
- ...q(b),
66
- children: /* @__PURE__ */ _("div", { className: "Button__content", children: [
67
- i && C !== "right" && /* @__PURE__ */ r(
68
- S,
69
- {
70
- mr: n && 0.5,
71
- name: i,
72
- color: a,
73
- rotation: I,
74
- size: R,
75
- spin: P
76
- }
77
- ),
78
- c ? /* @__PURE__ */ r(
79
- "span",
80
- {
81
- className: F([
82
- "Button--ellipsis",
83
- i && "Button__textMargin"
84
- ]),
85
- children: n
86
- }
87
- ) : n,
88
- i && C === "right" && /* @__PURE__ */ r(
89
- S,
90
- {
91
- ml: n && 0.5,
92
- name: i,
93
- color: a,
94
- rotation: I,
95
- size: R,
96
- spin: P
97
- }
98
- )
99
- ] })
65
+ ...q(g),
66
+ children: /* @__PURE__ */ _(
67
+ "div",
68
+ {
69
+ className: F([
70
+ "Button__content",
71
+ i && "Button__content--ellipsis"
72
+ ]),
73
+ children: [
74
+ c && C !== "right" && /* @__PURE__ */ r(
75
+ S,
76
+ {
77
+ mr: n && 0.5,
78
+ name: c,
79
+ color: a,
80
+ rotation: I,
81
+ size: R,
82
+ spin: P
83
+ }
84
+ ),
85
+ i ? /* @__PURE__ */ r("span", { className: "Button--ellipsis", children: n }) : n,
86
+ c && C === "right" && /* @__PURE__ */ r(
87
+ S,
88
+ {
89
+ ml: n && 0.5,
90
+ name: c,
91
+ color: a,
92
+ rotation: I,
93
+ size: R,
94
+ spin: P
95
+ }
96
+ )
97
+ ]
98
+ }
99
+ )
100
100
  }
101
101
  );
102
- return g && (k = /* @__PURE__ */ r(v, { content: g, position: w, children: k })), k;
102
+ return b && (k = /* @__PURE__ */ r(v, { content: b, position: w, children: k })), k;
103
103
  }
104
104
  function T(o) {
105
105
  const { checked: s, ...u } = o;
@@ -123,14 +123,14 @@ function L(o) {
123
123
  ellipsis: h = !0,
124
124
  icon: B,
125
125
  onClick: t,
126
- ...c
127
- } = o, [e, i] = A(!1);
126
+ ...i
127
+ } = o, [e, c] = A(!1);
128
128
  function a(C) {
129
129
  if (!e) {
130
- i(!0);
130
+ c(!0);
131
131
  return;
132
132
  }
133
- t == null || t(C), i(!1);
133
+ t == null || t(C), c(!1);
134
134
  }
135
135
  return /* @__PURE__ */ r(
136
136
  N,
@@ -138,12 +138,12 @@ function L(o) {
138
138
  icon: e ? l : B,
139
139
  color: e ? m : u,
140
140
  onClick: a,
141
- ...c,
141
+ ...i,
142
142
  children: e ? d : s
143
143
  }
144
144
  );
145
145
  }
146
- function M(o) {
146
+ function Y(o) {
147
147
  const {
148
148
  children: s,
149
149
  color: u = "default",
@@ -153,22 +153,22 @@ function M(o) {
153
153
  disabled: h,
154
154
  fluid: B,
155
155
  icon: t,
156
- iconRotation: c,
156
+ iconRotation: i,
157
157
  iconSpin: e,
158
- maxLength: i,
158
+ maxLength: c,
159
159
  onCommit: a = () => null,
160
160
  placeholder: C,
161
161
  tooltip: I,
162
162
  tooltipPosition: R,
163
163
  ...P
164
- } = o, [f, x] = A(!1), g = V(), w = m || s;
164
+ } = o, [f, x] = A(!1), b = V(), w = m || s;
165
165
  function y(n) {
166
- const k = g.current;
166
+ const k = b.current;
167
167
  if (!k) return;
168
168
  k.value !== "" ? a(n, k.value) : l && a(n, l);
169
169
  }
170
170
  $(() => {
171
- const n = g.current;
171
+ const n = b.current;
172
172
  if (n && f) {
173
173
  n.value = d || "";
174
174
  try {
@@ -177,7 +177,7 @@ function M(o) {
177
177
  }
178
178
  }
179
179
  }, [f, d]);
180
- let b = /* @__PURE__ */ _(
180
+ let g = /* @__PURE__ */ _(
181
181
  O,
182
182
  {
183
183
  className: F([
@@ -189,13 +189,13 @@ function M(o) {
189
189
  ...P,
190
190
  onClick: () => x(!0),
191
191
  children: [
192
- t && /* @__PURE__ */ r(S, { name: t, rotation: c, spin: e }),
192
+ t && /* @__PURE__ */ r(S, { name: t, rotation: i, spin: e }),
193
193
  /* @__PURE__ */ r("div", { children: w }),
194
194
  /* @__PURE__ */ r(
195
195
  "input",
196
196
  {
197
197
  disabled: !!h,
198
- ref: g,
198
+ ref: b,
199
199
  className: "NumberInput__input",
200
200
  style: {
201
201
  display: f ? "" : "none",
@@ -216,23 +216,23 @@ function M(o) {
216
216
  ]
217
217
  }
218
218
  );
219
- return I && (b = /* @__PURE__ */ r(v, { content: I, position: R, children: b })), b;
219
+ return I && (g = /* @__PURE__ */ r(v, { content: I, position: R, children: g })), g;
220
220
  }
221
- function Y(o) {
221
+ function G(o) {
222
222
  const { accept: s, multiple: u, onSelectFiles: m, ...d } = o, l = z(null);
223
223
  async function h(t) {
224
- const c = Array.from(t).map((e) => {
225
- const i = new FileReader();
224
+ const i = Array.from(t).map((e) => {
225
+ const c = new FileReader();
226
226
  return new Promise((a) => {
227
- i.onload = () => a(i.result), i.readAsText(e);
227
+ c.onload = () => a(c.result), c.readAsText(e);
228
228
  });
229
229
  });
230
- return await Promise.all(c);
230
+ return await Promise.all(i);
231
231
  }
232
232
  async function B(t) {
233
- const c = t.target.files;
234
- if (c != null && c.length) {
235
- const e = await h(c);
233
+ const i = t.target.files;
234
+ if (i != null && i.length) {
235
+ const e = await h(i);
236
236
  m(u ? e : e[0]);
237
237
  }
238
238
  }
@@ -255,7 +255,7 @@ function Y(o) {
255
255
  ] });
256
256
  }
257
257
  ((o) => {
258
- o.Checkbox = T, o.Confirm = L, o.Input = M, o.File = Y;
258
+ o.Checkbox = T, o.Confirm = L, o.Input = Y, o.File = G;
259
259
  })(N || (N = {}));
260
260
  export {
261
261
  N as Button
@@ -20,7 +20,7 @@ export type FlexProps = Partial<{
20
20
  */
21
21
  direction: string;
22
22
  /** Makes flexbox container inline, with similar behavior to an `inline` property on a `Box`. */
23
- inline: boolean;
23
+ inlineFlex: boolean;
24
24
  /**
25
25
  * This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are
26
26
  * inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow
@@ -1,70 +1,72 @@
1
1
  import { jsx as l } from "react/jsx-runtime";
2
- import { classes as r } from "../common/react.js";
2
+ import { classes as o } from "../common/react.js";
3
3
  import { computeBoxClassName as m, computeBoxProps as a, unit as f } from "../common/ui.js";
4
- function p(e) {
5
- return r([
4
+ function d(e) {
5
+ return o([
6
6
  "Flex",
7
- e.inline && "Flex--inline",
7
+ e.inlineFlex && "Flex--inline",
8
8
  m(e)
9
9
  ]);
10
10
  }
11
- function d(e) {
12
- const { direction: s, wrap: t, align: i, justify: n, ...o } = e;
11
+ function p(e) {
12
+ const { direction: i, wrap: t, align: r, justify: s, ...n } = e;
13
13
  return a({
14
14
  style: {
15
- ...o.style,
16
- flexDirection: s,
15
+ ...n.style,
16
+ flexDirection: i,
17
17
  flexWrap: t === !0 ? "wrap" : t,
18
- alignItems: i,
19
- justifyContent: n
18
+ alignItems: r,
19
+ justifyContent: s
20
20
  },
21
- ...o
21
+ ...n
22
22
  });
23
23
  }
24
24
  function F(e) {
25
- const { className: s, ...t } = e;
25
+ const { className: i, ...t } = e;
26
26
  return /* @__PURE__ */ l(
27
27
  "div",
28
28
  {
29
- className: r([s, p(t)]),
30
- ...d(t)
29
+ className: o([i, d(t)]),
30
+ ...p(t)
31
31
  }
32
32
  );
33
33
  }
34
- const N = (e) => r(["Flex__item", m(e)]);
34
+ const N = (e) => o(["Flex__item", m(e)]);
35
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
36
+ const { style: i, grow: t, order: r, shrink: s, basis: n, align: c, ...u } = e, x = n ?? // IE11: Set basis to specified width if it's known, which fixes certain
37
37
  // bugs when rendering tables inside the flex.
38
38
  e.width ?? // If grow is used, basis should be set to 0 to be consistent with
39
39
  // flex css shorthand `flex: 1`.
40
40
  (t !== void 0 ? 0 : void 0);
41
41
  return a({
42
42
  style: {
43
- ...s,
43
+ ...i,
44
+ minWidth: t !== void 0 && 0,
45
+ minHeight: t !== void 0 && 0,
44
46
  flexGrow: t !== void 0 && Number(t),
45
- flexShrink: n !== void 0 && Number(n),
47
+ flexShrink: s !== void 0 && Number(s),
46
48
  flexBasis: f(x),
47
- order: i,
49
+ order: r,
48
50
  alignSelf: c
49
51
  },
50
52
  ...u
51
53
  });
52
54
  }
53
- function y(e) {
54
- const { className: s, ...t } = e;
55
+ function g(e) {
56
+ const { className: i, ...t } = e;
55
57
  return /* @__PURE__ */ l(
56
58
  "div",
57
59
  {
58
- className: r([s, N(e)]),
60
+ className: o([i, N(e)]),
59
61
  ...v(t)
60
62
  }
61
63
  );
62
64
  }
63
- F.Item = y;
65
+ F.Item = g;
64
66
  export {
65
67
  F as Flex,
66
- p as computeFlexClassName,
68
+ d as computeFlexClassName,
67
69
  N as computeFlexItemClassName,
68
70
  v as computeFlexItemProps,
69
- d as computeFlexProps
71
+ p as computeFlexProps
70
72
  };
@@ -0,0 +1,35 @@
1
+ import { Component, PropsWithChildren } from 'react';
2
+ import { BoxProps } from './Box';
3
+ export type InfinitePlaneProps = PropsWithChildren<{
4
+ onZoomChange?: (newZoomValue: number) => void;
5
+ onBackgroundMoved?: (newX: number, newY: number) => void;
6
+ initialLeft?: number;
7
+ initialTop?: number;
8
+ backgroundImage?: string;
9
+ imageWidth: number;
10
+ } & BoxProps>;
11
+ type InfinitePlaneState = {
12
+ mouseDown: boolean;
13
+ left: number;
14
+ top: number;
15
+ lastLeft: number;
16
+ lastTop: number;
17
+ zoom: number;
18
+ };
19
+ export type MouseEventExtension = {
20
+ screenZoomX: number;
21
+ screenZoomY: number;
22
+ };
23
+ export declare class InfinitePlane extends Component<InfinitePlaneProps, InfinitePlaneState> {
24
+ constructor(props: InfinitePlaneProps);
25
+ componentDidMount(): void;
26
+ componentWillUnmount(): void;
27
+ doOffsetMouse: (event: MouseEvent & MouseEventExtension) => void;
28
+ handleMouseDown: (event: React.MouseEvent<HTMLDivElement>) => void;
29
+ onMouseUp: () => void;
30
+ handleZoomIncrease: (_event: any) => void;
31
+ handleZoomDecrease: (_event: any) => void;
32
+ handleMouseMove: (event: React.MouseEvent<HTMLDivElement>) => void;
33
+ render(): import("react/jsx-runtime").JSX.Element;
34
+ }
35
+ export {};
@@ -1,20 +1,63 @@
1
- import { jsxs as l, jsx as n } from "react/jsx-runtime";
2
- import { Component as v } from "react";
3
- import { computeBoxProps as Z } from "../common/ui.js";
4
- import { Button as c } from "./Button.js";
5
- import { ProgressBar as g } from "./ProgressBar.js";
6
- import { Stack as d } from "./Stack.js";
7
- const p = 0.5, f = 1.5, M = 0.1;
8
- class k extends v {
9
- constructor(e) {
10
- super(e), this.state = {
1
+ var x = Object.defineProperty;
2
+ var O = (a, s, o) => s in a ? x(a, s, { enumerable: !0, configurable: !0, writable: !0, value: o }) : a[s] = o;
3
+ var i = (a, s, o) => O(a, typeof s != "symbol" ? s + "" : s, o);
4
+ import { jsxs as c, jsx as r } from "react/jsx-runtime";
5
+ import { Component as Z } from "react";
6
+ import { computeBoxProps as D } from "../common/ui.js";
7
+ import { Button as w } from "./Button.js";
8
+ import { ProgressBar as E } from "./ProgressBar.js";
9
+ import { Stack as h } from "./Stack.js";
10
+ const M = 0.5, v = 1.5, g = 0.1;
11
+ class b extends Z {
12
+ constructor(o) {
13
+ super(o);
14
+ // This is really, REALLY cursed and basically overrides a built-in browser event via propagation rules
15
+ i(this, "doOffsetMouse", (o) => {
16
+ const { zoom: e } = this.state;
17
+ o.screenZoomX = o.screenX * e ** -1, o.screenZoomY = o.screenY * e ** -1;
18
+ });
19
+ i(this, "handleMouseDown", (o) => {
20
+ this.setState((e) => ({
21
+ mouseDown: !0,
22
+ lastLeft: o.clientX - e.left,
23
+ lastTop: o.clientY - e.top
24
+ }));
25
+ });
26
+ i(this, "onMouseUp", () => {
27
+ this.setState({
28
+ mouseDown: !1
29
+ });
30
+ });
31
+ i(this, "handleZoomIncrease", (o) => {
32
+ const { onZoomChange: e } = this.props, { zoom: n } = this.state, t = Math.min(n + g, v);
33
+ this.setState({
34
+ zoom: t
35
+ }), e && e(t);
36
+ });
37
+ i(this, "handleZoomDecrease", (o) => {
38
+ const { onZoomChange: e } = this.props, { zoom: n } = this.state, t = Math.max(n - g, M);
39
+ this.setState({
40
+ zoom: t
41
+ }), e && e(t);
42
+ });
43
+ i(this, "handleMouseMove", (o) => {
44
+ const { onBackgroundMoved: e, initialLeft: n = 0, initialTop: t = 0 } = this.props;
45
+ if (this.state.mouseDown) {
46
+ let l, m;
47
+ this.setState((d) => (l = o.clientX - d.lastLeft, m = o.clientY - d.lastTop, e && e(l + n, m + t), {
48
+ left: l,
49
+ top: m
50
+ }));
51
+ }
52
+ });
53
+ this.state = {
11
54
  mouseDown: !1,
12
55
  left: 0,
13
56
  top: 0,
14
57
  lastLeft: 0,
15
58
  lastTop: 0,
16
59
  zoom: 1
17
- }, this.handleMouseDown = this.handleMouseDown.bind(this), this.handleMouseMove = this.handleMouseMove.bind(this), this.handleZoomIncrease = this.handleZoomIncrease.bind(this), this.handleZoomDecrease = this.handleZoomDecrease.bind(this), this.onMouseUp = this.onMouseUp.bind(this), this.doOffsetMouse = this.doOffsetMouse.bind(this);
60
+ };
18
61
  }
19
62
  componentDidMount() {
20
63
  window.addEventListener("mouseup", this.onMouseUp), window.addEventListener("mousedown", this.doOffsetMouse), window.addEventListener("mousemove", this.doOffsetMouse), window.addEventListener("mouseup", this.doOffsetMouse);
@@ -22,67 +65,28 @@ class k extends v {
22
65
  componentWillUnmount() {
23
66
  window.removeEventListener("mouseup", this.onMouseUp), window.removeEventListener("mousedown", this.doOffsetMouse), window.removeEventListener("mousemove", this.doOffsetMouse), window.removeEventListener("mouseup", this.doOffsetMouse);
24
67
  }
25
- doOffsetMouse(e) {
26
- const { zoom: o } = this.state;
27
- e.screenZoomX = e.screenX * o ** -1, e.screenZoomY = e.screenY * o ** -1;
28
- }
29
- handleMouseDown(e) {
30
- this.setState((o) => ({
31
- mouseDown: !0,
32
- lastLeft: e.clientX - o.left,
33
- lastTop: e.clientY - o.top
34
- }));
35
- }
36
- onMouseUp() {
37
- this.setState({
38
- mouseDown: !1
39
- });
40
- }
41
- handleZoomIncrease(e) {
42
- const { onZoomChange: o } = this.props, { zoom: s } = this.state, t = Math.min(s + M, f);
43
- this.setState({
44
- zoom: t
45
- }), o && o(t);
46
- }
47
- handleZoomDecrease(e) {
48
- const { onZoomChange: o } = this.props, { zoom: s } = this.state, t = Math.max(s - M, p);
49
- this.setState({
50
- zoom: t
51
- }), o && o(t);
52
- }
53
- handleMouseMove(e) {
54
- const { onBackgroundMoved: o, initialLeft: s = 0, initialTop: t = 0 } = this.props;
55
- if (this.state.mouseDown) {
56
- let a, i;
57
- this.setState((h) => (a = e.clientX - h.lastLeft, i = e.clientY - h.lastTop, {
58
- left: a,
59
- top: i
60
- })), o && o(a + s, i + t);
61
- }
62
- }
63
68
  render() {
64
69
  const {
65
- children: e,
66
- backgroundImage: o,
67
- imageWidth: s,
70
+ children: o,
71
+ backgroundImage: e,
72
+ imageWidth: n,
68
73
  initialLeft: t = 0,
69
- initialTop: a = 0,
70
- ...i
71
- } = this.props, { left: h, top: w, zoom: r } = this.state, m = t + h, u = a + w;
72
- return /* @__PURE__ */ l(
74
+ initialTop: l = 0,
75
+ ...m
76
+ } = this.props, { left: d, top: L, zoom: u } = this.state, p = t + d, f = l + L;
77
+ return /* @__PURE__ */ c(
73
78
  "div",
74
79
  {
75
- ref: this.ref,
76
- ...Z({
77
- ...i,
80
+ ...D({
81
+ ...m,
78
82
  style: {
79
- ...i.style,
83
+ ...m.style,
80
84
  overflow: "hidden",
81
85
  position: "relative"
82
86
  }
83
87
  }),
84
88
  children: [
85
- /* @__PURE__ */ n(
89
+ /* @__PURE__ */ r(
86
90
  "div",
87
91
  {
88
92
  onMouseDown: this.handleMouseDown,
@@ -91,43 +95,43 @@ class k extends v {
91
95
  position: "fixed",
92
96
  height: "100%",
93
97
  width: "100%",
94
- backgroundImage: `url("${o}")`,
95
- backgroundPosition: `${m}px ${u}px`,
98
+ backgroundImage: `url("${e}")`,
99
+ backgroundPosition: `${p}px ${f}px`,
96
100
  backgroundRepeat: "repeat",
97
- backgroundSize: `${r * s}px`
101
+ backgroundSize: `${u * n}px`
98
102
  }
99
103
  }
100
104
  ),
101
- /* @__PURE__ */ n(
105
+ /* @__PURE__ */ r(
102
106
  "div",
103
107
  {
104
108
  onMouseDown: this.handleMouseDown,
105
109
  onMouseMove: this.handleMouseMove,
106
110
  style: {
107
111
  position: "fixed",
108
- transform: `translate(${m}px, ${u}px) scale(${r})`,
112
+ transform: `translate(${p}px, ${f}px) scale(${u})`,
109
113
  transformOrigin: "top left",
110
114
  height: "100%",
111
115
  width: "100%"
112
116
  },
113
- children: e
117
+ children: o
114
118
  }
115
119
  ),
116
- /* @__PURE__ */ l(d, { position: "absolute", width: "100%", children: [
117
- /* @__PURE__ */ n(d.Item, { children: /* @__PURE__ */ n(c, { icon: "minus", onClick: this.handleZoomDecrease }) }),
118
- /* @__PURE__ */ n(d.Item, { grow: 1, children: /* @__PURE__ */ l(
119
- g,
120
+ /* @__PURE__ */ c(h, { position: "absolute", width: "100%", children: [
121
+ /* @__PURE__ */ r(h.Item, { children: /* @__PURE__ */ r(w, { icon: "minus", onClick: this.handleZoomDecrease }) }),
122
+ /* @__PURE__ */ r(h.Item, { grow: 1, children: /* @__PURE__ */ c(
123
+ E,
120
124
  {
121
- minValue: p,
122
- value: r,
123
- maxValue: f,
125
+ minValue: M,
126
+ value: u,
127
+ maxValue: v,
124
128
  children: [
125
- r,
129
+ u,
126
130
  "x"
127
131
  ]
128
132
  }
129
133
  ) }),
130
- /* @__PURE__ */ n(d.Item, { children: /* @__PURE__ */ n(c, { icon: "plus", onClick: this.handleZoomIncrease }) })
134
+ /* @__PURE__ */ r(h.Item, { children: /* @__PURE__ */ r(w, { icon: "plus", onClick: this.handleZoomIncrease }) })
131
135
  ] })
132
136
  ]
133
137
  }
@@ -135,5 +139,5 @@ class k extends v {
135
139
  }
136
140
  }
137
141
  export {
138
- k as InfinitePlane
142
+ b as InfinitePlane
139
143
  };
@@ -1,4 +1,11 @@
1
+ import { KeyboardEvent } from 'react';
1
2
  import { BoxProps } from './Box';
3
+ export type ModalProps = BoxProps & Partial<{
4
+ /** Fires once the enter key is pressed */
5
+ onEnter: (e: KeyboardEvent<HTMLInputElement>) => void;
6
+ /** Fires once the escape key is pressed */
7
+ onEscape: (e: KeyboardEvent<HTMLInputElement>) => void;
8
+ }>;
2
9
  /**
3
10
  * ## Modal
4
11
  * A modal window. Uses a [Dimmer](https://github.com/tgstation/tgui-core/tree/main/lib/components/Dimmer.tsx)
@@ -6,4 +13,4 @@ import { BoxProps } from './Box';
6
13
  *
7
14
  * Must be a direct child of a layout component (e.g. `Window`).
8
15
  */
9
- export declare function Modal(props: BoxProps): import("react/jsx-runtime").JSX.Element;
16
+ export declare function Modal(props: ModalProps): import("react/jsx-runtime").JSX.Element;
@@ -1,18 +1,22 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { classes as t } from "../common/react.js";
3
- import { computeBoxClassName as a, computeBoxProps as c } from "../common/ui.js";
4
- import { Dimmer as i } from "./Dimmer.js";
5
- function f(m) {
6
- const { className: s, children: e, ...o } = m;
7
- return /* @__PURE__ */ r(i, { children: /* @__PURE__ */ r(
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { KEY as n, isEscape as f } from "../common/keys.js";
3
+ import { classes as l } from "../common/react.js";
4
+ import { computeBoxClassName as p, computeBoxProps as d } from "../common/ui.js";
5
+ import { Dimmer as u } from "./Dimmer.js";
6
+ function N(s) {
7
+ const { className: t, children: a, onEnter: r, onEscape: m, ...e } = s;
8
+ function c(o) {
9
+ o.key === n.Enter && (r == null || r(o)), f(o.key) && (m == null || m(o));
10
+ }
11
+ return /* @__PURE__ */ i(u, { onKeyDown: c, children: /* @__PURE__ */ i(
8
12
  "div",
9
13
  {
10
- className: t(["Modal", s, a(o)]),
11
- ...c(o),
12
- children: e
14
+ className: l(["Modal", t, p(e)]),
15
+ ...d(e),
16
+ children: a
13
17
  }
14
18
  ) });
15
19
  }
16
20
  export {
17
- f as Modal
21
+ N as Modal
18
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tgui-core",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "TGUI core component library",
5
5
  "keywords": ["TGUI", "library", "typescript"],
6
6
  "files": ["dist", "styles"],
@@ -31,7 +31,8 @@
31
31
  "lint": "biome check lib",
32
32
  "lint:fix": "prettier . --write && biome check . --fix",
33
33
  "storybook": "storybook dev -p 6006",
34
- "build-storybook": "storybook build"
34
+ "build-storybook": "storybook build",
35
+ "test": "node --experimental-strip-types --experimental-test-coverage --test ./tests/*.test.ts"
35
36
  },
36
37
  "author": "jlsnow301",
37
38
  "license": "MIT",
@@ -47,8 +48,8 @@
47
48
  "@storybook/blocks": "^8.4.7",
48
49
  "@storybook/react": "^8.4.7",
49
50
  "@storybook/react-vite": "^8.4.7",
50
- "@storybook/theming": "^8.4.7",
51
51
  "@storybook/test": "^8.4.7",
52
+ "@storybook/theming": "^8.4.7",
52
53
  "@types/node": "^22.9.0",
53
54
  "@types/react": "^18.3.3",
54
55
  "@types/react-dom": "^18.3.0",
@@ -91,6 +91,7 @@ $bg-map: colors.$bg-map !default;
91
91
  display: block;
92
92
  text-overflow: ellipsis;
93
93
  overflow: hidden;
94
+ margin-right: -0.33em;
94
95
  }
95
96
 
96
97
  .Button--fluid {
@@ -164,8 +165,9 @@ $bg-map: colors.$bg-map !default;
164
165
  .Button__content {
165
166
  display: block;
166
167
  align-self: stretch;
167
- }
168
168
 
169
- .Button__textMargin {
170
- margin-left: 0.4rem;
169
+ &--ellipsis {
170
+ display: flex; // Inline flex will broke ellipsis, don't change it.
171
+ align-items: center;
172
+ }
171
173
  }
@@ -14,5 +14,6 @@ $background-dimness: 0.75 !default;
14
14
  right: 0;
15
15
  // Dim everything around it
16
16
  background-color: rgba(0, 0, 0, $background-dimness);
17
- z-index: 1;
17
+ // Should be enough to cover everything except tooltips
18
+ z-index: 100;
18
19
  }
@@ -6,7 +6,6 @@ $background-color: hsl(0, 0%, 0%) !default;
6
6
  $border-radius: base.$border-radius !default;
7
7
 
8
8
  .Tooltip {
9
- z-index: 2;
10
9
  padding: 0.5em 0.75em;
11
10
  pointer-events: none;
12
11
  text-align: left;
@@ -16,4 +15,6 @@ $border-radius: base.$border-radius !default;
16
15
  box-shadow: 0.1em 0.1em 1.25em -0.1em rgba(0, 0, 0, 0.5);
17
16
  border-radius: $border-radius;
18
17
  max-width: base.em(250px);
18
+ // Must be over everything
19
+ z-index: 999;
19
20
  }