tgui-core 2.0.6 → 2.1.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 (120) hide show
  1. package/dist/common/collections.d.ts +1 -1
  2. package/dist/common/collections.js +1 -10
  3. package/dist/common/color.js +1 -70
  4. package/dist/common/constants.js +1 -329
  5. package/dist/common/events.js +1 -147
  6. package/dist/common/exhaustive.js +1 -6
  7. package/dist/common/format.js +1 -117
  8. package/dist/common/fp.js +1 -9
  9. package/dist/common/hotkeys.d.ts +1 -1
  10. package/dist/common/hotkeys.js +1 -112
  11. package/dist/common/http.js +1 -10
  12. package/dist/common/keycodes.js +1 -88
  13. package/dist/common/keys.js +1 -32
  14. package/dist/common/math.js +1 -45
  15. package/dist/common/random.js +1 -21
  16. package/dist/common/react.js +1 -30
  17. package/dist/common/string.js +1 -88
  18. package/dist/common/timer.js +1 -28
  19. package/dist/common/type-utils.js +1 -25
  20. package/dist/common/ui.d.ts +2 -2
  21. package/dist/common/ui.js +1 -141
  22. package/dist/common/uuid.js +1 -10
  23. package/dist/common/vector.js +1 -48
  24. package/dist/components/AnimatedNumber.d.ts +1 -1
  25. package/dist/components/AnimatedNumber.js +1 -73
  26. package/dist/components/Autofocus.d.ts +1 -1
  27. package/dist/components/Autofocus.js +1 -17
  28. package/dist/components/Blink.d.ts +1 -1
  29. package/dist/components/Blink.js +1 -56
  30. package/dist/components/BlockQuote.d.ts +1 -1
  31. package/dist/components/BlockQuote.js +1 -10
  32. package/dist/components/Box.d.ts +5 -5
  33. package/dist/components/Box.js +1 -19
  34. package/dist/components/Button.d.ts +4 -4
  35. package/dist/components/Button.js +1 -258
  36. package/dist/components/ByondUi.d.ts +1 -1
  37. package/dist/components/ByondUi.js +1 -61
  38. package/dist/components/Chart.d.ts +1 -1
  39. package/dist/components/Chart.js +1 -80
  40. package/dist/components/Collapsible.d.ts +2 -2
  41. package/dist/components/Collapsible.js +1 -36
  42. package/dist/components/ColorBox.d.ts +2 -2
  43. package/dist/components/ColorBox.js +1 -17
  44. package/dist/components/Dialog.d.ts +1 -1
  45. package/dist/components/Dialog.js +1 -42
  46. package/dist/components/Dimmer.d.ts +1 -1
  47. package/dist/components/Dimmer.js +1 -10
  48. package/dist/components/Divider.js +1 -18
  49. package/dist/components/DmIcon.d.ts +3 -3
  50. package/dist/components/DmIcon.js +1 -23
  51. package/dist/components/DraggableControl.d.ts +2 -2
  52. package/dist/components/DraggableControl.js +1 -111
  53. package/dist/components/Dropdown.d.ts +2 -2
  54. package/dist/components/Dropdown.js +1 -165
  55. package/dist/components/FitText.d.ts +2 -2
  56. package/dist/components/FitText.js +1 -63
  57. package/dist/components/Flex.d.ts +1 -1
  58. package/dist/components/Flex.js +1 -70
  59. package/dist/components/Floating.d.ts +3 -3
  60. package/dist/components/Floating.js +1 -2235
  61. package/dist/components/Icon.d.ts +2 -2
  62. package/dist/components/Icon.js +1 -45
  63. package/dist/components/Image.d.ts +1 -1
  64. package/dist/components/Image.js +1 -38
  65. package/dist/components/ImageButton.d.ts +10 -5
  66. package/dist/components/ImageButton.js +1 -154
  67. package/dist/components/InfinitePlane.d.ts +2 -2
  68. package/dist/components/InfinitePlane.js +1 -133
  69. package/dist/components/Input.d.ts +2 -2
  70. package/dist/components/Input.js +1 -96
  71. package/dist/components/KeyListener.d.ts +1 -1
  72. package/dist/components/KeyListener.js +1 -15
  73. package/dist/components/Knob.d.ts +2 -2
  74. package/dist/components/Knob.js +1 -133
  75. package/dist/components/LabeledControls.d.ts +1 -1
  76. package/dist/components/LabeledControls.js +1 -39
  77. package/dist/components/LabeledList.d.ts +2 -2
  78. package/dist/components/LabeledList.js +1 -89
  79. package/dist/components/MenuBar.d.ts +32 -0
  80. package/dist/components/MenuBar.js +1 -133
  81. package/dist/components/Modal.d.ts +2 -2
  82. package/dist/components/Modal.js +1 -22
  83. package/dist/components/NoticeBox.d.ts +1 -1
  84. package/dist/components/NoticeBox.js +1 -23
  85. package/dist/components/NumberInput.d.ts +9 -19
  86. package/dist/components/NumberInput.js +1 -213
  87. package/dist/components/Popper.d.ts +8 -9
  88. package/dist/components/Popper.js +1 -1082
  89. package/dist/components/ProgressBar.d.ts +2 -2
  90. package/dist/components/ProgressBar.js +1 -33
  91. package/dist/components/RestrictedInput.d.ts +29 -0
  92. package/dist/components/RestrictedInput.js +1 -161
  93. package/dist/components/RoundGauge.d.ts +2 -2
  94. package/dist/components/RoundGauge.js +1 -114
  95. package/dist/components/Section.d.ts +2 -2
  96. package/dist/components/Section.js +1 -65
  97. package/dist/components/Slider.d.ts +2 -2
  98. package/dist/components/Slider.js +1 -113
  99. package/dist/components/Stack.d.ts +2 -2
  100. package/dist/components/Stack.js +1 -58
  101. package/dist/components/StyleableSection.d.ts +1 -1
  102. package/dist/components/StyleableSection.js +1 -16
  103. package/dist/components/Table.d.ts +1 -1
  104. package/dist/components/Table.js +1 -57
  105. package/dist/components/Tabs.d.ts +2 -2
  106. package/dist/components/Tabs.js +1 -65
  107. package/dist/components/TextArea.d.ts +2 -2
  108. package/dist/components/TextArea.js +1 -126
  109. package/dist/components/TimeDisplay.js +1 -25
  110. package/dist/components/Tooltip.d.ts +2 -2
  111. package/dist/components/Tooltip.js +1 -18
  112. package/dist/components/TrackOutsideClicks.d.ts +2 -2
  113. package/dist/components/TrackOutsideClicks.js +1 -24
  114. package/dist/components/VirtualList.d.ts +1 -1
  115. package/dist/components/VirtualList.js +1 -34
  116. package/dist/components/index.js +1 -96
  117. package/license.txt +1 -1
  118. package/package.json +11 -17
  119. package/styles/components/Button.scss +1 -1
  120. package/dist/components/FakeTerminal.js +0 -38
@@ -1,5 +1,5 @@
1
- import { BooleanLike } from '../common/react';
2
- import { BoxProps } from './Box';
1
+ import { type BooleanLike } from '../common/react';
2
+ import type { BoxProps } from './Box';
3
3
  type Props = {
4
4
  /** Icon name. @see https://fontawesome.com/v6/search?o=r&m=free */
5
5
  name: string;
@@ -1,45 +1 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import { classes as p } from "../common/react.js";
3
- import { computeBoxProps as u, computeBoxClassName as N } from "../common/ui.js";
4
- const f = /-o$/;
5
- function m(o) {
6
- const { name: s = "", size: a, spin: e, className: x, rotation: r, ...c } = o, n = c.style || {};
7
- a && (n.fontSize = `${a * 100}%`), r && (n.transform = `rotate(${r}deg)`), c.style = n;
8
- const I = u(c);
9
- let t = "";
10
- if (s.startsWith("tg-"))
11
- t = s;
12
- else {
13
- const S = f.test(s), i = s.replace(f, ""), d = !i.startsWith("fa-");
14
- t = S ? "far " : "fas ", d && (t += "fa-"), t += i, e && (t += " fa-spin");
15
- }
16
- return /* @__PURE__ */ l(
17
- "i",
18
- {
19
- className: p([
20
- "Icon",
21
- t,
22
- x,
23
- N(c)
24
- ]),
25
- ...I
26
- }
27
- );
28
- }
29
- function g(o) {
30
- const { className: s, children: a, ...e } = o;
31
- return /* @__PURE__ */ l(
32
- "span",
33
- {
34
- className: p(["IconStack", s, N(e)]),
35
- ...u(e),
36
- children: a
37
- }
38
- );
39
- }
40
- ((o) => {
41
- o.Stack = g;
42
- })(m || (m = {}));
43
- export {
44
- m as Icon
45
- };
1
+ import*as s from"react/jsx-runtime";import*as t from"../common/react.js";import*as e from"../common/ui.js";let o=/-o$/;function a(a){let{name:r="",size:c,spin:m,className:n,rotation:l,...i}=a,f=i.style||{};c&&(f.fontSize=`${100*c}%`),l&&(f.transform=`rotate(${l}deg)`),i.style=f;let p=(0,e.computeBoxProps)(i),u="";if(r.startsWith("tg-"))u=r;else{let s=o.test(r),t=r.replace(o,""),e=!t.startsWith("fa-");u=s?"far ":"fas ",e&&(u+="fa-"),u+=t,m&&(u+=" fa-spin")}return(0,s.jsx)("i",{className:(0,t.classes)(["Icon",u,n,(0,e.computeBoxClassName)(i)]),...p})}(a||(a={})).Stack=function(o){let{className:a,children:r,...c}=o;return(0,s.jsx)("span",{className:(0,t.classes)(["IconStack",a,(0,e.computeBoxClassName)(c)]),...(0,e.computeBoxProps)(c),children:r})};export{a as Icon};
@@ -1,4 +1,4 @@
1
- import { BoxProps } from './Box';
1
+ import type { BoxProps } from './Box';
2
2
  type Props = Partial<{
3
3
  className: string;
4
4
  /** True is default, this fixes an ie thing */
@@ -1,38 +1 @@
1
- import { jsx as c } from "react/jsx-runtime";
2
- import { useRef as p } from "react";
3
- import { computeBoxProps as u } from "../common/ui.js";
4
- const g = 5;
5
- function C(o) {
6
- const {
7
- fixBlur: r = !0,
8
- fixErrors: m = !1,
9
- objectFit: s = "fill",
10
- src: A,
11
- ...n
12
- } = o, t = p(0), e = u(n);
13
- return e.style = {
14
- ...e.style,
15
- "-ms-interpolation-mode": r ? "nearest-neighbor" : "auto",
16
- imageRendering: r ? "pixelated" : "auto",
17
- objectFit: s
18
- }, /* @__PURE__ */ c(
19
- "img",
20
- {
21
- onError: (i) => {
22
- if (m && t.current < g) {
23
- const a = i.currentTarget;
24
- setTimeout(() => {
25
- a.src = `${A}?attempt=${t.current}`, t.current++;
26
- }, 1e3);
27
- }
28
- },
29
- src: A || /** Use transparent base64 pixel if there is no src. So we don't get broken image icon when using assets */
30
- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
31
- ...e,
32
- alt: "dm icon"
33
- }
34
- );
35
- }
36
- export {
37
- C as Image
38
- };
1
+ import*as e from"react/jsx-runtime";import*as A from"react";import*as t from"../common/ui.js";function r(r){let{fixBlur:o=!0,fixErrors:m=!1,objectFit:a="fill",src:i,...n}=r,s=(0,A.useRef)(0),u=(0,t.computeBoxProps)(n);return u.style={...u.style,"-ms-interpolation-mode":o?"nearest-neighbor":"auto",imageRendering:o?"pixelated":"auto",objectFit:a},(0,e.jsx)("img",{onError:e=>{if(m&&s.current<5){let A=e.currentTarget;setTimeout(()=>{A.src=`${i}?attempt=${s.current}`,s.current++},1e3)}},src:i||"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",...u,alt:"dm icon"})}export{r as Image};
@@ -1,8 +1,13 @@
1
- import { Placement } from '@floating-ui/react';
2
- import { ReactNode } from 'react';
3
- import { BooleanLike } from '../common/react';
4
- import { BoxProps } from './Box';
5
- import { Direction } from './DmIcon';
1
+ /**
2
+ * @file
3
+ * @copyright 2024 Aylong (https://github.com/AyIong)
4
+ * @license MIT
5
+ */
6
+ import type { Placement } from '@floating-ui/react';
7
+ import type { ReactNode } from 'react';
8
+ import { type BooleanLike } from '../common/react';
9
+ import type { BoxProps } from './Box';
10
+ import { type Direction } from './DmIcon';
6
11
  type Props = Partial<{
7
12
  /** Asset cache. Example: `asset={['assetname32x32', thing.key]}` */
8
13
  asset: string[];
@@ -1,154 +1 @@
1
- import { jsxs as g, jsx as t } from "react/jsx-runtime";
2
- import { classes as c } from "../common/react.js";
3
- import { computeBoxProps as D } from "../common/ui.js";
4
- import { DmIcon as j } from "./DmIcon.js";
5
- import { Icon as A } from "./Icon.js";
6
- import { Image as y } from "./Image.js";
7
- import { Stack as N } from "./Stack.js";
8
- import { Tooltip as F } from "./Tooltip.js";
9
- function W(r) {
10
- const {
11
- asset: l,
12
- assetSize: u = 32,
13
- base64: o,
14
- buttons: _,
15
- buttonsAlt: h,
16
- children: n,
17
- className: k,
18
- color: d,
19
- disabled: a,
20
- dmFallback: v,
21
- dmIcon: I,
22
- dmIconState: f,
23
- fluid: s,
24
- imageSize: e = 64,
25
- imageSrc: x,
26
- onClick: m,
27
- onRightClick: B,
28
- selected: z,
29
- title: b,
30
- tooltip: $,
31
- tooltipPosition: S,
32
- ...C
33
- } = r;
34
- let p = /* @__PURE__ */ g(
35
- "div",
36
- {
37
- className: "ImageButton__container",
38
- tabIndex: a ? void 0 : 0,
39
- onClick: (i) => {
40
- !a && m && m(i);
41
- },
42
- onKeyDown: (i) => {
43
- i.key === "Enter" && !a && m && m(i);
44
- },
45
- onContextMenu: (i) => {
46
- i.preventDefault(), !a && B && B(i);
47
- },
48
- style: { width: s ? "auto" : `calc(${e}px + 0.5em + 2px)` },
49
- children: [
50
- /* @__PURE__ */ t("div", { className: "ImageButton__image", children: o || x ? /* @__PURE__ */ t(
51
- y,
52
- {
53
- src: o ? `data:image/png;base64,${o}` : x,
54
- height: `${e}px`,
55
- width: `${e}px`
56
- }
57
- ) : I && f ? /* @__PURE__ */ t(
58
- j,
59
- {
60
- icon: I,
61
- icon_state: f,
62
- fallback: v || /* @__PURE__ */ t(w, { icon: "spinner", spin: !0, size: e }),
63
- height: `${e}px`,
64
- width: `${e}px`
65
- }
66
- ) : l ? /* @__PURE__ */ t(
67
- y,
68
- {
69
- className: c(l || []),
70
- height: `${e}px`,
71
- width: `${e}px`,
72
- style: {
73
- transform: `scale(${e / u})`,
74
- transformOrigin: "top left"
75
- }
76
- }
77
- ) : /* @__PURE__ */ t(w, { icon: "question", size: e }) }),
78
- s ? /* @__PURE__ */ g("div", { className: "ImageButton__content", children: [
79
- b && /* @__PURE__ */ t(
80
- "span",
81
- {
82
- className: c([
83
- "ImageButton__content--title",
84
- !!n && "ImageButton__content--divider"
85
- ]),
86
- children: b
87
- }
88
- ),
89
- n && /* @__PURE__ */ t("span", { className: "ImageButton__content--text", children: n })
90
- ] }) : !!n && /* @__PURE__ */ t("span", { className: "ImageButton__content", children: n })
91
- ]
92
- }
93
- );
94
- return $ && (p = /* @__PURE__ */ t(F, { content: $, position: S, children: p })), /* @__PURE__ */ g(
95
- "div",
96
- {
97
- className: c([
98
- "ImageButton",
99
- s && "ImageButton--fluid",
100
- z && "ImageButton--selected",
101
- a && "ImageButton--disabled",
102
- d && typeof d == "string" ? `ImageButton__color--${d}` : "ImageButton__color--default",
103
- k
104
- ]),
105
- ...D(C),
106
- children: [
107
- p,
108
- _ && /* @__PURE__ */ t(
109
- "div",
110
- {
111
- className: c([
112
- "ImageButton__buttons",
113
- !n && "ImageButton__buttons--empty"
114
- ]),
115
- style: {
116
- width: "auto"
117
- },
118
- children: _
119
- }
120
- ),
121
- h && /* @__PURE__ */ t(
122
- "div",
123
- {
124
- className: c([
125
- "ImageButton__buttons",
126
- "ImageButton__buttons--alt",
127
- !n && "ImageButton__buttons--empty"
128
- ]),
129
- style: {
130
- width: `calc(${e}px + ${s ? 0 : 0.5}em)`,
131
- maxWidth: s ? "auto" : `calc(${e}px + 0.5em)`
132
- },
133
- children: h
134
- }
135
- )
136
- ]
137
- }
138
- );
139
- }
140
- function w(r) {
141
- const { icon: l, spin: u = !1, size: o = 64 } = r;
142
- return /* @__PURE__ */ t(N, { height: `${o}px`, width: `${o}px`, children: /* @__PURE__ */ t(N.Item, { grow: !0, textAlign: "center", align: "center", children: /* @__PURE__ */ t(
143
- A,
144
- {
145
- spin: u,
146
- name: l,
147
- color: "gray",
148
- style: { fontSize: `calc(${o}px * 0.75)` }
149
- }
150
- ) }) });
151
- }
152
- export {
153
- W as ImageButton
154
- };
1
+ import*as t from"react/jsx-runtime";import*as e from"../common/react.js";import*as s from"../common/ui.js";import*as n from"./DmIcon.js";import*as o from"./Icon.js";import*as a from"./Image.js";import*as i from"./Stack.js";import*as c from"./Tooltip.js";function m(o){let{asset:i,assetSize:m=32,base64:r,buttons:p,buttonsAlt:u,children:x,className:d,color:g,disabled:_,dmFallback:h,dmIcon:I,dmIconState:j,fluid:B,imageSize:f=64,imageSrc:$,onClick:y,onRightClick:N,selected:b,title:v,tooltip:w,tooltipPosition:k,...D}=o,S=(0,t.jsxs)("div",{className:"ImageButton__container",tabIndex:_?void 0:0,onClick:t=>{!_&&y&&y(t)},onKeyDown:t=>{"Enter"===t.key&&!_&&y&&y(t)},onContextMenu:t=>{t.preventDefault(),!_&&N&&N(t)},style:{width:B?"auto":`calc(${f}px + 0.5em + 2px)`},children:[(0,t.jsx)("div",{className:"ImageButton__image",children:r||$?(0,t.jsx)(a.Image,{src:r?`data:image/png;base64,${r}`:$,height:`${f}px`,width:`${f}px`}):I&&j?(0,t.jsx)(n.DmIcon,{icon:I,icon_state:j,fallback:h||(0,t.jsx)(l,{icon:"spinner",spin:!0,size:f}),height:`${f}px`,width:`${f}px`}):i?(0,t.jsx)(a.Image,{className:(0,e.classes)(i||[]),height:`${f}px`,width:`${f}px`,style:{transform:`scale(${f/m})`,transformOrigin:"top left"}}):(0,t.jsx)(l,{icon:"question",size:f})}),B?(0,t.jsxs)("div",{className:"ImageButton__content",children:[v&&(0,t.jsx)("span",{className:(0,e.classes)(["ImageButton__content--title",!!x&&"ImageButton__content--divider"]),children:v}),x&&(0,t.jsx)("span",{className:"ImageButton__content--text",children:x})]}):!!x&&(0,t.jsx)("span",{className:"ImageButton__content",children:x})]});return w&&(S=(0,t.jsx)(c.Tooltip,{content:w,position:k,children:S})),(0,t.jsxs)("div",{className:(0,e.classes)(["ImageButton",B&&"ImageButton--fluid",b&&"ImageButton--selected",_&&"ImageButton--disabled",g&&"string"==typeof g?`ImageButton__color--${g}`:"ImageButton__color--default",d]),...(0,s.computeBoxProps)(D),children:[S,p&&(0,t.jsx)("div",{className:(0,e.classes)(["ImageButton__buttons",!x&&"ImageButton__buttons--empty"]),style:{width:"auto"},children:p}),u&&(0,t.jsx)("div",{className:(0,e.classes)(["ImageButton__buttons","ImageButton__buttons--alt",!x&&"ImageButton__buttons--empty"]),style:{width:`calc(${f}px + ${.5*!B}em)`,maxWidth:B?"auto":`calc(${f}px + 0.5em)`},children:u})]})}function l(e){let{icon:s,spin:n=!1,size:a=64}=e;return(0,t.jsx)(i.Stack,{height:`${a}px`,width:`${a}px`,children:(0,t.jsx)(i.Stack.Item,{grow:!0,textAlign:"center",align:"center",children:(0,t.jsx)(o.Icon,{spin:n,name:s,color:"gray",style:{fontSize:`calc(${a}px * 0.75)`}})})})}export{m as ImageButton};
@@ -1,5 +1,5 @@
1
- import { PropsWithChildren } from 'react';
2
- import { BoxProps } from './Box';
1
+ import { type PropsWithChildren } from 'react';
2
+ import type { BoxProps } from './Box';
3
3
  type Props = {
4
4
  /** The width of the image to display. */
5
5
  imageWidth: number;
@@ -1,133 +1 @@
1
- import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
- import { useState as i, useEffect as z } from "react";
3
- import { computeBoxProps as A } from "../common/ui.js";
4
- import { Button as O } from "./Button.js";
5
- import { ProgressBar as N } from "./ProgressBar.js";
6
- import { Stack as c } from "./Stack.js";
7
- const f = 0.5, p = 1.5, S = 0.1;
8
- function F(l) {
9
- const {
10
- backgroundImage: t,
11
- children: r,
12
- imageWidth: $,
13
- initialLeft: h = 0,
14
- initialTop: w = 0,
15
- onBackgroundMoved: a,
16
- onZoomChange: u,
17
- ...M
18
- } = l, [E, T] = i(0), [y, C] = i(0), [g, D] = i(0), [_, v] = i(!1), [x, P] = i(0), [n, V] = i(1);
19
- function L(e) {
20
- T(e.clientX - g), C(e.clientY - x), v(!0);
21
- }
22
- function b(e) {
23
- if (!_) return;
24
- const m = e.clientX - E, s = e.clientY - y;
25
- a == null || a(m + h, s + w), D(m), P(s);
26
- }
27
- function k() {
28
- v(!1);
29
- }
30
- function X(e) {
31
- if (e === "increase" && n >= p || e === "decrease" && n <= f) return;
32
- const s = Math.round((n + (e === "increase" ? S : -0.1)) * 10) / 10;
33
- V(s), u == null || u(s);
34
- }
35
- z(() => (window.addEventListener("mouseup", k), () => {
36
- window.removeEventListener("mouseup", k);
37
- }), []);
38
- const I = h + g, Z = w + x;
39
- return /* @__PURE__ */ d(
40
- "div",
41
- {
42
- ...A({
43
- ...M,
44
- style: {
45
- ...M.style,
46
- height: "100%",
47
- overflow: "hidden",
48
- position: "relative",
49
- width: "100%"
50
- }
51
- }),
52
- children: [
53
- /* @__PURE__ */ o(
54
- "div",
55
- {
56
- onMouseDown: L,
57
- onMouseMove: b,
58
- style: {
59
- backgroundImage: `url("${t}")`,
60
- backgroundPosition: `${I}px ${Z}px`,
61
- backgroundRepeat: "repeat",
62
- backgroundSize: `${n * $}px`,
63
- height: "100%",
64
- inset: 0,
65
- position: "absolute",
66
- width: "100%"
67
- }
68
- }
69
- ),
70
- /* @__PURE__ */ o(
71
- "div",
72
- {
73
- onMouseDown: L,
74
- onMouseMove: b,
75
- style: {
76
- height: "100%",
77
- inset: 0,
78
- pointerEvents: "none",
79
- position: "absolute",
80
- transform: `translate(${I}px, ${Z}px) scale(${n})`,
81
- transformOrigin: "top left",
82
- width: "100%"
83
- },
84
- children: r
85
- }
86
- ),
87
- /* @__PURE__ */ o(Y, { zoom: n, onZoomClick: X })
88
- ]
89
- }
90
- );
91
- }
92
- function Y(l) {
93
- const { zoom: t, onZoomClick: r } = l;
94
- return /* @__PURE__ */ o("div", { style: { position: "absolute", top: 5, left: 5, right: 5 }, children: /* @__PURE__ */ d(c, { children: [
95
- /* @__PURE__ */ o(c.Item, { children: /* @__PURE__ */ o(
96
- O,
97
- {
98
- icon: "minus",
99
- disabled: t <= f,
100
- onClick: () => r(
101
- "decrease"
102
- /* Decrease */
103
- )
104
- }
105
- ) }),
106
- /* @__PURE__ */ o(c.Item, { grow: !0, children: /* @__PURE__ */ d(
107
- N,
108
- {
109
- minValue: f,
110
- value: t,
111
- maxValue: p,
112
- children: [
113
- t,
114
- "x"
115
- ]
116
- }
117
- ) }),
118
- /* @__PURE__ */ o(c.Item, { children: /* @__PURE__ */ o(
119
- O,
120
- {
121
- icon: "plus",
122
- disabled: t >= p,
123
- onClick: () => r(
124
- "increase"
125
- /* Increase */
126
- )
127
- }
128
- ) })
129
- ] }) });
130
- }
131
- export {
132
- F as InfinitePlane
133
- };
1
+ import*as e from"react/jsx-runtime";import*as t from"react";import*as o from"../common/ui.js";import*as n from"./Button.js";import*as i from"./ProgressBar.js";import*as s from"./Stack.js";function r(n){let{backgroundImage:i,children:s,imageWidth:r,initialLeft:u=0,initialTop:c=0,onBackgroundMoved:l,onZoomChange:d,...m}=n,[p,f]=(0,t.useState)(0),[x,h]=(0,t.useState)(0),[j,g]=(0,t.useState)(0),[v,k]=(0,t.useState)(!1),[S,w]=(0,t.useState)(0),[b,M]=(0,t.useState)(1);function $(e){f(e.clientX-j),h(e.clientY-S),k(!0)}function B(e){if(!v)return;let t=e.clientX-p,o=e.clientY-x;l?.(t+u,o+c),g(t),w(o)}function y(){k(!1)}(0,t.useEffect)(()=>(window.addEventListener("mouseup",y),()=>{window.removeEventListener("mouseup",y)}),[]);let I=u+j,P=c+S;return(0,e.jsxs)("div",{...(0,o.computeBoxProps)({...m,style:{...m.style,height:"100%",overflow:"hidden",position:"relative",width:"100%"}}),children:[(0,e.jsx)("div",{onMouseDown:$,onMouseMove:B,style:{backgroundImage:`url("${i}")`,backgroundPosition:`${I}px ${P}px`,backgroundRepeat:"repeat",backgroundSize:`${b*r}px`,height:"100%",inset:0,position:"absolute",width:"100%"}}),(0,e.jsx)("div",{onMouseDown:$,onMouseMove:B,style:{height:"100%",inset:0,pointerEvents:"none",position:"absolute",transform:`translate(${I}px, ${P}px) scale(${b})`,transformOrigin:"top left",width:"100%"},children:s}),(0,e.jsx)(a,{zoom:b,onZoomClick:function(e){if("increase"===e&&b>=1.5||"decrease"===e&&b<=.5)return;let t=Math.round((b+("increase"===e?.1:-.1))*10)/10;M(t),d?.(t)}})]})}function a(t){let{zoom:o,onZoomClick:r}=t;return(0,e.jsx)("div",{style:{position:"absolute",top:5,left:5,right:5},children:(0,e.jsxs)(s.Stack,{children:[(0,e.jsx)(s.Stack.Item,{children:(0,e.jsx)(n.Button,{icon:"minus",disabled:o<=.5,onClick:()=>r("decrease")})}),(0,e.jsx)(s.Stack.Item,{grow:!0,children:(0,e.jsxs)(i.ProgressBar,{minValue:.5,value:o,maxValue:1.5,children:[o,"x"]})}),(0,e.jsx)(s.Stack.Item,{children:(0,e.jsx)(n.Button,{icon:"plus",disabled:o>=1.5,onClick:()=>r("increase")})})]})})}export{r as InfinitePlane};
@@ -1,5 +1,5 @@
1
- import { SyntheticEvent } from 'react';
2
- import { BoxProps } from './Box';
1
+ import { type SyntheticEvent } from 'react';
2
+ import { type BoxProps } from './Box';
3
3
  type ConditionalProps = {
4
4
  /**
5
5
  * Mark this if you want to debounce onInput.
@@ -1,96 +1 @@
1
- import { jsxs as S, jsx as p } from "react/jsx-runtime";
2
- import { useRef as j, useEffect as m } from "react";
3
- import { KEY as k, isEscape as v } from "../common/keys.js";
4
- import { classes as w } from "../common/react.js";
5
- import { debounce as B } from "../common/timer.js";
6
- import { Box as F } from "./Box.js";
7
- function d(r) {
8
- return typeof r != "number" && typeof r != "string" ? "" : String(r);
9
- }
10
- const O = B((r) => r(), 250);
11
- function z(r) {
12
- const {
13
- autoFocus: g,
14
- autoSelect: l,
15
- className: I,
16
- disabled: T,
17
- expensive: b,
18
- fluid: h,
19
- maxLength: x,
20
- monospace: y,
21
- onChange: n,
22
- onEnter: o,
23
- onEscape: s,
24
- onInput: a,
25
- placeholder: E,
26
- selfClear: N,
27
- updateOnPropsChange: _,
28
- value: c,
29
- ...A
30
- } = r, i = j(null);
31
- function D(t) {
32
- var u;
33
- if (!a) return;
34
- const e = (u = t.currentTarget) == null ? void 0 : u.value;
35
- b ? O(() => a(t, e)) : a(t, e);
36
- }
37
- function K(t) {
38
- if (t.key === k.Enter) {
39
- o == null || o(t, t.currentTarget.value), N ? t.currentTarget.value = "" : (t.currentTarget.blur(), n == null || n(t, t.currentTarget.value));
40
- return;
41
- }
42
- v(t.key) && (s == null || s(t), t.currentTarget.value = d(c), t.currentTarget.blur());
43
- }
44
- function f(t) {
45
- const e = i.current;
46
- if (!e) return;
47
- const u = d(t);
48
- e.value !== u && (e.value = u);
49
- }
50
- return m(() => {
51
- const t = i.current;
52
- if (t) {
53
- f(c);
54
- const e = g || l, u = document.activeElement === t;
55
- e && !u && setTimeout(() => {
56
- t.focus(), l && t.select();
57
- }, 1);
58
- }
59
- }, []), m(() => {
60
- if (_) {
61
- const t = i.current;
62
- t && (document.activeElement === t || f(c));
63
- }
64
- }, [c]), /* @__PURE__ */ S(
65
- F,
66
- {
67
- className: w([
68
- "Input",
69
- h && "Input--fluid",
70
- y && "Input--monospace",
71
- I
72
- ]),
73
- ...A,
74
- children: [
75
- /* @__PURE__ */ p("div", { className: "Input__baseline", children: "." }),
76
- /* @__PURE__ */ p(
77
- "input",
78
- {
79
- className: "Input__input",
80
- disabled: T,
81
- maxLength: x,
82
- onBlur: (t) => n == null ? void 0 : n(t, t.target.value),
83
- onChange: D,
84
- onKeyDown: K,
85
- placeholder: E,
86
- ref: i
87
- }
88
- )
89
- ]
90
- }
91
- );
92
- }
93
- export {
94
- z as Input,
95
- d as toInputValue
96
- };
1
+ import*as e from"react/jsx-runtime";import*as t from"react";import*as r from"../common/keys.js";import*as n from"../common/react.js";import*as u from"../common/timer.js";import*as a from"./Box.js";function o(e){return"number"!=typeof e&&"string"!=typeof e?"":String(e)}let c=(0,u.debounce)(e=>e(),250);function s(u){let{autoFocus:s,autoSelect:l,className:i,disabled:m,expensive:f,fluid:p,maxLength:g,monospace:v,onChange:d,onEnter:j,onEscape:x,onInput:T,placeholder:E,selfClear:I,updateOnPropsChange:b,value:y,...h}=u,_=(0,t.useRef)(null);function k(e){let t=_.current;if(!t)return;let r=o(e);t.value!==r&&(t.value=r)}return(0,t.useEffect)(()=>{let e=_.current;if(e){k(y);let t=document.activeElement===e;(s||l)&&!t&&setTimeout(()=>{e.focus(),l&&e.select()},1)}},[]),(0,t.useEffect)(()=>{if(b){let e=_.current;e&&document.activeElement!==e&&k(y)}},[y]),(0,e.jsxs)(a.Box,{className:(0,n.classes)(["Input",p&&"Input--fluid",v&&"Input--monospace",i]),...h,children:[(0,e.jsx)("div",{className:"Input__baseline",children:"."}),(0,e.jsx)("input",{className:"Input__input",disabled:m,maxLength:g,onBlur:e=>d?.(e,e.target.value),onChange:function(e){if(!T)return;let t=e.currentTarget?.value;f?c(()=>T(e,t)):T(e,t)},onKeyDown:function(e){if(e.key===r.KEY.Enter){j?.(e,e.currentTarget.value),I?e.currentTarget.value="":(e.currentTarget.blur(),d?.(e,e.currentTarget.value));return}(0,r.isEscape)(e.key)&&(x?.(e),e.currentTarget.value=o(y),e.currentTarget.blur())},placeholder:E,ref:_})]})}export{s as Input,o as toInputValue};
@@ -1,4 +1,4 @@
1
- import { KeyEvent } from '../common/events';
1
+ import type { KeyEvent } from '../common/events';
2
2
  type Props = Partial<{
3
3
  onKey: (key: KeyEvent) => void;
4
4
  onKeyDown: (key: KeyEvent) => void;
@@ -1,15 +1 @@
1
- import { useEffect as i } from "react";
2
- import { listenForKeyEvents as t } from "../common/hotkeys.js";
3
- function r(n) {
4
- return i(() => {
5
- const o = t((e) => {
6
- n.onKey && n.onKey(e), e.isDown() && n.onKeyDown && n.onKeyDown(e), e.isUp() && n.onKeyUp && n.onKeyUp(e);
7
- });
8
- return () => {
9
- o();
10
- };
11
- }, []), null;
12
- }
13
- export {
14
- r as KeyListener
15
- };
1
+ import*as e from"react";import*as o from"../common/hotkeys.js";function n(n){return(0,e.useEffect)(()=>{let e=(0,o.listenForKeyEvents)(e=>{n.onKey&&n.onKey(e),e.isDown()&&n.onKeyDown&&n.onKeyDown(e),e.isUp()&&n.onKeyUp&&n.onKeyUp(e)});return()=>{e()}},[]),null}export{n as KeyListener};
@@ -1,5 +1,5 @@
1
- import { BooleanLike } from '../common/react';
2
- import { BoxProps } from './Box';
1
+ import { type BooleanLike } from '../common/react';
2
+ import type { BoxProps } from './Box';
3
3
  type Props = {
4
4
  /** Value itself, controls the position of the cursor. */
5
5
  value: number;