tgui-core 1.1.11 → 1.1.13
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.
- package/dist/ProgressBar.module-BkAFfFy0.js +29 -0
- package/dist/Section.module-CLVHJ4yA.js +15 -0
- package/dist/assets/BlockQuote.css +1 -0
- package/dist/assets/Button.css +1 -0
- package/dist/assets/ColorBox.css +1 -0
- package/dist/assets/Dialog.css +1 -0
- package/dist/assets/Dimmer.css +1 -0
- package/dist/assets/Divider.css +1 -0
- package/dist/assets/Flex.css +1 -0
- package/dist/assets/Icon.css +6 -0
- package/dist/assets/Input.css +1 -0
- package/dist/assets/Knob.css +1 -0
- package/dist/assets/LabeledList.css +1 -0
- package/dist/assets/MenuBar.css +1 -0
- package/dist/assets/Modal.css +1 -0
- package/dist/assets/NoticeBox.css +1 -0
- package/dist/assets/NumberInput.css +1 -0
- package/dist/assets/ProgressBar.css +1 -0
- package/dist/assets/RoundGauge.css +1 -0
- package/dist/assets/Section.css +1 -0
- package/dist/assets/Slider.css +1 -0
- package/dist/assets/Stack.css +1 -0
- package/dist/assets/Table.css +1 -0
- package/dist/assets/Tabs.css +1 -0
- package/dist/assets/TextArea.css +1 -0
- package/dist/assets/Tooltip.css +1 -0
- package/dist/common/assets.d.ts +4 -0
- package/dist/common/assets.js +25 -0
- package/dist/common/collections.d.ts +10 -0
- package/dist/common/collections.js +15 -0
- package/dist/common/color.d.ts +25 -0
- package/dist/common/color.js +69 -0
- package/dist/common/constants.d.ts +102 -0
- package/dist/common/constants.js +312 -0
- package/dist/common/events.d.ts +33 -0
- package/dist/common/events.js +147 -0
- package/{lib/common/exhaustive.ts → dist/common/exhaustive.d.ts} +1 -3
- package/dist/common/exhaustive.js +6 -0
- package/dist/common/format.d.ts +11 -0
- package/dist/common/format.js +114 -0
- package/{lib/common/fp.ts → dist/common/fp.d.ts} +2 -16
- package/dist/common/fp.js +9 -0
- package/dist/common/hotkeys.d.ts +25 -0
- package/dist/common/hotkeys.js +112 -0
- package/dist/common/http.d.ts +4 -0
- package/dist/common/http.js +10 -0
- package/dist/common/keycodes.d.ts +85 -0
- package/dist/common/keycodes.js +88 -0
- package/{lib/common/keys.ts → dist/common/keys.d.ts} +21 -24
- package/dist/common/keys.js +8 -0
- package/dist/common/math.d.ts +39 -0
- package/dist/common/math.js +41 -0
- package/dist/common/perf.d.ts +24 -0
- package/dist/common/perf.js +33 -0
- package/dist/common/random.d.ts +16 -0
- package/dist/common/random.js +18 -0
- package/dist/common/react.d.ts +23 -0
- package/dist/common/react.js +30 -0
- package/dist/common/redux.d.ts +64 -0
- package/dist/common/redux.js +72 -0
- package/dist/common/storage.d.ts +24 -0
- package/dist/common/storage.js +133 -0
- package/dist/common/string.d.ts +65 -0
- package/dist/common/string.js +83 -0
- package/dist/common/timer.d.ts +18 -0
- package/dist/common/timer.js +28 -0
- package/dist/common/type-utils.d.ts +9 -0
- package/dist/common/type-utils.js +25 -0
- package/dist/common/uuid.d.ts +9 -0
- package/dist/common/uuid.js +10 -0
- package/dist/components/AnimatedNumber.d.ts +60 -0
- package/dist/components/AnimatedNumber.js +76 -0
- package/dist/components/Autofocus.d.ts +4 -0
- package/dist/components/Autofocus.js +17 -0
- package/dist/components/Blink.d.ts +26 -0
- package/dist/components/Blink.js +56 -0
- package/dist/components/BlockQuote.d.ts +3 -0
- package/dist/components/BlockQuote.js +13 -0
- package/dist/components/BodyZoneSelector.d.ts +28 -0
- package/dist/components/BodyZoneSelector.js +115 -0
- package/dist/components/Box.d.ts +91 -0
- package/dist/components/Box.js +133 -0
- package/dist/components/Button.d.ts +93 -0
- package/dist/components/Button.js +298 -0
- package/dist/components/ByondUi.js +73 -0
- package/dist/components/Chart.d.ts +28 -0
- package/dist/components/Chart.js +95 -0
- package/dist/components/Collapsible.d.ts +15 -0
- package/dist/components/Collapsible.js +27 -0
- package/dist/components/ColorBox.d.ts +8 -0
- package/dist/components/ColorBox.js +24 -0
- package/dist/components/Dialog.d.ts +24 -0
- package/dist/components/Dialog.js +67 -0
- package/dist/components/Dimmer.d.ts +3 -0
- package/dist/components/Dimmer.js +13 -0
- package/dist/components/Divider.d.ts +6 -0
- package/dist/components/Divider.js +22 -0
- package/dist/components/DmIcon.d.ts +33 -0
- package/dist/components/DmIcon.js +29 -0
- package/dist/components/DraggableControl.js +176 -0
- package/dist/components/Dropdown.d.ts +48 -0
- package/dist/components/Dropdown.js +152 -0
- package/dist/components/FakeTerminal.js +38 -0
- package/dist/components/FitText.d.ts +22 -0
- package/dist/components/FitText.js +63 -0
- package/dist/components/Flex.d.ts +93 -0
- package/dist/components/Flex.js +72 -0
- package/dist/components/Icon.d.ts +30 -0
- package/dist/components/Icon.js +51 -0
- package/dist/components/Image.d.ts +14 -0
- package/dist/components/Image.js +35 -0
- package/dist/components/InfinitePlane.js +139 -0
- package/dist/components/Input.d.ts +61 -0
- package/dist/components/Input.js +89 -0
- package/dist/components/KeyListener.d.ts +15 -0
- package/dist/components/KeyListener.js +23 -0
- package/dist/components/Knob.d.ts +49 -0
- package/dist/components/Knob.js +162 -0
- package/dist/components/LabeledControls.d.ts +11 -0
- package/dist/components/LabeledControls.js +39 -0
- package/dist/components/LabeledList.d.ts +57 -0
- package/dist/components/LabeledList.js +94 -0
- package/dist/components/MenuBar.d.ts +28 -0
- package/dist/components/MenuBar.js +174 -0
- package/dist/components/Modal.d.ts +3 -0
- package/dist/components/Modal.js +25 -0
- package/dist/components/NoticeBox.d.ts +20 -0
- package/dist/components/NoticeBox.js +49 -0
- package/dist/components/NumberInput.d.ts +45 -0
- package/dist/components/NumberInput.js +221 -0
- package/dist/components/Popper.d.ts +27 -0
- package/dist/components/Popper.js +177 -0
- package/dist/components/ProgressBar.d.ts +46 -0
- package/dist/components/ProgressBar.js +37 -0
- package/dist/components/RestrictedInput.js +155 -0
- package/dist/components/RoundGauge.d.ts +53 -0
- package/dist/components/RoundGauge.js +147 -0
- package/dist/components/Section.d.ts +63 -0
- package/dist/components/Section.js +62 -0
- package/dist/components/Slider.d.ts +46 -0
- package/dist/components/Slider.js +124 -0
- package/dist/components/Stack.d.ts +27 -0
- package/dist/components/Stack.js +67 -0
- package/dist/components/StyleableSection.d.ts +11 -0
- package/dist/components/StyleableSection.js +16 -0
- package/dist/components/Table.d.ts +29 -0
- package/dist/components/Table.js +67 -0
- package/dist/components/Tabs.d.ts +23 -0
- package/dist/components/Tabs.js +89 -0
- package/dist/components/TextArea.d.ts +39 -0
- package/dist/components/TextArea.js +118 -0
- package/dist/components/TimeDisplay.js +34 -0
- package/dist/components/Tooltip.d.ts +29 -0
- package/dist/components/Tooltip.js +83 -0
- package/dist/components/TrackOutsideClicks.d.ts +13 -0
- package/dist/components/TrackOutsideClicks.js +24 -0
- package/dist/components/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList.js +34 -0
- package/dist/components/index.js +92 -0
- package/dist/popper-CiqSDJTE.js +906 -0
- package/package.json +8 -10
- package/lib/common/assets.ts +0 -38
- package/lib/common/collections.ts +0 -27
- package/lib/common/color.ts +0 -88
- package/lib/common/constants.ts +0 -349
- package/lib/common/events.ts +0 -262
- package/lib/common/format.ts +0 -167
- package/lib/common/hotkeys.ts +0 -207
- package/lib/common/http.ts +0 -16
- package/lib/common/keycodes.ts +0 -86
- package/lib/common/math.ts +0 -76
- package/lib/common/perf.ts +0 -72
- package/lib/common/random.ts +0 -32
- package/lib/common/react.ts +0 -59
- package/lib/common/redux.ts +0 -187
- package/lib/common/storage.ts +0 -207
- package/lib/common/string.ts +0 -169
- package/lib/common/timer.ts +0 -63
- package/lib/common/type-utils.ts +0 -41
- package/lib/common/types.d.ts +0 -12
- package/lib/common/uuid.ts +0 -18
- package/lib/components/AnimatedNumber.tsx +0 -180
- package/lib/components/Autofocus.tsx +0 -23
- package/lib/components/Blink.tsx +0 -91
- package/lib/components/BlockQuote.tsx +0 -9
- package/lib/components/BodyZoneSelector.tsx +0 -149
- package/lib/components/Box.tsx +0 -252
- package/lib/components/Button.tsx +0 -425
- package/lib/components/ByondUi.jsx +0 -110
- package/lib/components/Chart.tsx +0 -155
- package/lib/components/Collapsible.tsx +0 -43
- package/lib/components/ColorBox.tsx +0 -29
- package/lib/components/Dialog.tsx +0 -81
- package/lib/components/Dimmer.tsx +0 -13
- package/lib/components/Divider.tsx +0 -20
- package/lib/components/DmIcon.tsx +0 -86
- package/lib/components/DraggableControl.jsx +0 -276
- package/lib/components/Dropdown.tsx +0 -246
- package/lib/components/FakeTerminal.jsx +0 -52
- package/lib/components/FitText.tsx +0 -99
- package/lib/components/Flex.tsx +0 -159
- package/lib/components/Icon.tsx +0 -95
- package/lib/components/Image.tsx +0 -54
- package/lib/components/InfinitePlane.jsx +0 -192
- package/lib/components/Input.tsx +0 -176
- package/lib/components/KeyListener.tsx +0 -40
- package/lib/components/Knob.tsx +0 -178
- package/lib/components/LabeledControls.tsx +0 -44
- package/lib/components/LabeledList.tsx +0 -154
- package/lib/components/MenuBar.tsx +0 -228
- package/lib/components/Modal.tsx +0 -23
- package/lib/components/NoticeBox.tsx +0 -45
- package/lib/components/NumberInput.tsx +0 -328
- package/lib/components/Popper.tsx +0 -100
- package/lib/components/ProgressBar.tsx +0 -105
- package/lib/components/RestrictedInput.jsx +0 -301
- package/lib/components/RoundGauge.tsx +0 -180
- package/lib/components/Section.tsx +0 -120
- package/lib/components/Slider.tsx +0 -169
- package/lib/components/Stack.tsx +0 -96
- package/lib/components/StyleableSection.tsx +0 -33
- package/lib/components/Table.tsx +0 -84
- package/lib/components/Tabs.tsx +0 -89
- package/lib/components/TextArea.tsx +0 -182
- package/lib/components/TimeDisplay.jsx +0 -64
- package/lib/components/Tooltip.tsx +0 -152
- package/lib/components/TrackOutsideClicks.tsx +0 -35
- package/lib/components/VirtualList.tsx +0 -69
- package/lib/styles/atomic/candystripe.scss +0 -8
- package/lib/styles/atomic/centered-image.scss +0 -7
- package/lib/styles/atomic/color.scss +0 -21
- package/lib/styles/atomic/debug-layout.scss +0 -17
- package/lib/styles/atomic/fit-text.scss +0 -14
- package/lib/styles/atomic/links.scss +0 -12
- package/lib/styles/atomic/outline.scss +0 -47
- package/lib/styles/atomic/text.scss +0 -44
- package/lib/styles/base.scss +0 -32
- package/lib/styles/colors.scss +0 -92
- package/lib/styles/components/BlockQuote.module.scss +0 -20
- package/lib/styles/components/BlockQuote.module.scss.d.ts +0 -4
- package/lib/styles/components/Button.module.scss +0 -157
- package/lib/styles/components/Button.module.scss.d.ts +0 -46
- package/lib/styles/components/ColorBox.module.scss +0 -12
- package/lib/styles/components/ColorBox.module.scss.d.ts +0 -4
- package/lib/styles/components/Dialog.module.scss +0 -60
- package/lib/styles/components/Dialog.module.scss.d.ts +0 -10
- package/lib/styles/components/Dimmer.module.scss +0 -22
- package/lib/styles/components/Dimmer.module.scss.d.ts +0 -4
- package/lib/styles/components/Divider.module.scss +0 -27
- package/lib/styles/components/Divider.module.scss.d.ts +0 -6
- package/lib/styles/components/Dropdown.scss +0 -72
- package/lib/styles/components/Flex.module.scss +0 -13
- package/lib/styles/components/Flex.module.scss.d.ts +0 -5
- package/lib/styles/components/Icon.module.scss +0 -25
- package/lib/styles/components/Icon.module.scss.d.ts +0 -5
- package/lib/styles/components/Input.module.scss +0 -64
- package/lib/styles/components/Input.module.scss.d.ts +0 -8
- package/lib/styles/components/Knob.module.scss +0 -131
- package/lib/styles/components/Knob.module.scss.d.ts +0 -33
- package/lib/styles/components/LabeledList.module.scss +0 -49
- package/lib/styles/components/LabeledList.module.scss.d.ts +0 -8
- package/lib/styles/components/MenuBar.module.scss +0 -75
- package/lib/styles/components/MenuBar.module.scss.d.ts +0 -14
- package/lib/styles/components/Modal.module.scss +0 -14
- package/lib/styles/components/Modal.module.scss.d.ts +0 -4
- package/lib/styles/components/NoticeBox.module.scss +0 -65
- package/lib/styles/components/NoticeBox.module.scss.d.ts +0 -27
- package/lib/styles/components/NumberInput.module.scss +0 -71
- package/lib/styles/components/NumberInput.module.scss.d.ts +0 -9
- package/lib/styles/components/ProgressBar.module.scss +0 -63
- package/lib/styles/components/ProgressBar.module.scss.d.ts +0 -27
- package/lib/styles/components/RoundGauge.module.scss +0 -85
- package/lib/styles/components/RoundGauge.module.scss.d.ts +0 -49
- package/lib/styles/components/Section.module.scss +0 -130
- package/lib/styles/components/Section.module.scss.d.ts +0 -13
- package/lib/styles/components/Slider.module.scss +0 -54
- package/lib/styles/components/Slider.module.scss.d.ts +0 -8
- package/lib/styles/components/Stack.module.scss +0 -60
- package/lib/styles/components/Stack.module.scss.d.ts +0 -12
- package/lib/styles/components/Table.module.scss +0 -44
- package/lib/styles/components/Table.module.scss.d.ts +0 -10
- package/lib/styles/components/Tabs.module.scss +0 -144
- package/lib/styles/components/Tabs.module.scss.d.ts +0 -35
- package/lib/styles/components/TextArea.module.scss +0 -86
- package/lib/styles/components/TextArea.module.scss.d.ts +0 -11
- package/lib/styles/components/Tooltip.module.scss +0 -24
- package/lib/styles/components/Tooltip.module.scss.d.ts +0 -4
- package/lib/styles/functions.scss +0 -79
- package/lib/styles/input.scss +0 -9
- package/lib/styles/main.scss +0 -20
- package/lib/styles/reset.scss +0 -68
- /package/{lib/components/index.ts → dist/components/index.d.ts} +0 -0
package/lib/components/Blink.tsx
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Component, PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type Props = Partial<{
|
|
5
|
-
/**
|
|
6
|
-
* The interval between blinks, in milliseconds.
|
|
7
|
-
*/
|
|
8
|
-
interval: number;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The time to wait before blinking again, in milliseconds.
|
|
12
|
-
*/
|
|
13
|
-
time: number;
|
|
14
|
-
}> & PropsWithChildren;
|
|
15
|
-
|
|
16
|
-
type State = {
|
|
17
|
-
hidden: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const DEFAULT_BLINKING_INTERVAL = 1000;
|
|
21
|
-
const DEFAULT_BLINKING_TIME = 1000;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export class Blink extends Component<Props, State> {
|
|
26
|
-
interval: NodeJS.Timeout;
|
|
27
|
-
timer: NodeJS.Timeout;
|
|
28
|
-
|
|
29
|
-
constructor(props) {
|
|
30
|
-
super(props);
|
|
31
|
-
this.state = {
|
|
32
|
-
hidden: false,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
createTimer() {
|
|
37
|
-
const {
|
|
38
|
-
interval = DEFAULT_BLINKING_INTERVAL,
|
|
39
|
-
time = DEFAULT_BLINKING_TIME,
|
|
40
|
-
} = this.props;
|
|
41
|
-
|
|
42
|
-
clearInterval(this.interval);
|
|
43
|
-
clearTimeout(this.timer);
|
|
44
|
-
|
|
45
|
-
this.setState({
|
|
46
|
-
hidden: false,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
this.interval = setInterval(() => {
|
|
50
|
-
this.setState({
|
|
51
|
-
hidden: true,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.timer = setTimeout(() => {
|
|
55
|
-
this.setState({
|
|
56
|
-
hidden: false,
|
|
57
|
-
});
|
|
58
|
-
}, time);
|
|
59
|
-
}, interval + time);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
componentDidMount() {
|
|
63
|
-
this.createTimer();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
componentDidUpdate(prevProps) {
|
|
67
|
-
if (
|
|
68
|
-
prevProps.interval !== this.props.interval ||
|
|
69
|
-
prevProps.time !== this.props.time
|
|
70
|
-
) {
|
|
71
|
-
this.createTimer();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
componentWillUnmount() {
|
|
76
|
-
clearInterval(this.interval);
|
|
77
|
-
clearTimeout(this.timer);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
return (
|
|
82
|
-
<span
|
|
83
|
-
style={{
|
|
84
|
-
visibility: this.state.hidden ? 'hidden' : 'visible',
|
|
85
|
-
}}
|
|
86
|
-
>
|
|
87
|
-
{this.props.children}
|
|
88
|
-
</span>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { classes } from '../common/react';
|
|
2
|
-
import styles from '../styles/components/BlockQuote.module.scss';
|
|
3
|
-
import { Box, BoxProps } from './Box';
|
|
4
|
-
|
|
5
|
-
export function BlockQuote(props: BoxProps) {
|
|
6
|
-
const { className, ...rest } = props;
|
|
7
|
-
|
|
8
|
-
return <Box className={classes([styles.blockQuote, className])} {...rest} />;
|
|
9
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { Component, createRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { resolveAsset } from '../common/assets';
|
|
4
|
-
import { Image } from './Image';
|
|
5
|
-
|
|
6
|
-
export enum BodyZone {
|
|
7
|
-
Chest = 'chest',
|
|
8
|
-
Eyes = 'eyes',
|
|
9
|
-
Groin = 'groin',
|
|
10
|
-
Head = 'head',
|
|
11
|
-
LeftArm = 'l_arm',
|
|
12
|
-
LeftLeg = 'l_leg',
|
|
13
|
-
Mouth = 'mouth',
|
|
14
|
-
RightArm = 'r_arm',
|
|
15
|
-
RightLeg = 'r_leg',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const bodyZonePixelToZone = (x: number, y: number): BodyZone | null => {
|
|
19
|
-
// TypeScript translation of /atom/movable/screen/zone_sel/proc/get_zone_at
|
|
20
|
-
if (y < 1) {
|
|
21
|
-
return null;
|
|
22
|
-
} else if (y < 10) {
|
|
23
|
-
if (x > 10 && x < 15) {
|
|
24
|
-
return BodyZone.RightLeg;
|
|
25
|
-
} else if (x > 17 && x < 22) {
|
|
26
|
-
return BodyZone.LeftLeg;
|
|
27
|
-
}
|
|
28
|
-
} else if (y < 13) {
|
|
29
|
-
if (x > 8 && x < 11) {
|
|
30
|
-
return BodyZone.RightArm;
|
|
31
|
-
} else if (x > 12 && x < 20) {
|
|
32
|
-
return BodyZone.Groin;
|
|
33
|
-
} else if (x > 21 && x < 24) {
|
|
34
|
-
return BodyZone.LeftArm;
|
|
35
|
-
}
|
|
36
|
-
} else if (y < 22) {
|
|
37
|
-
if (x > 8 && x < 11) {
|
|
38
|
-
return BodyZone.RightArm;
|
|
39
|
-
} else if (x > 12 && x < 20) {
|
|
40
|
-
return BodyZone.Chest;
|
|
41
|
-
} else if (x > 21 && x < 24) {
|
|
42
|
-
return BodyZone.LeftArm;
|
|
43
|
-
}
|
|
44
|
-
} else if (y < 30 && x > 12 && x < 20) {
|
|
45
|
-
if (y > 23 && y < 24 && x > 15 && x < 17) {
|
|
46
|
-
return BodyZone.Mouth;
|
|
47
|
-
} else if (y > 25 && y < 27 && x > 14 && x < 18) {
|
|
48
|
-
return BodyZone.Eyes;
|
|
49
|
-
} else {
|
|
50
|
-
return BodyZone.Head;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return null;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type BodyZoneSelectorProps = {
|
|
58
|
-
onClick?: (zone: BodyZone) => void;
|
|
59
|
-
scale?: number;
|
|
60
|
-
selectedZone: BodyZone | null;
|
|
61
|
-
theme?: string;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
type BodyZoneSelectorState = {
|
|
65
|
-
hoverZone: BodyZone | null;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export class BodyZoneSelector extends Component<
|
|
69
|
-
BodyZoneSelectorProps,
|
|
70
|
-
BodyZoneSelectorState
|
|
71
|
-
> {
|
|
72
|
-
ref = createRef<HTMLDivElement>();
|
|
73
|
-
state: BodyZoneSelectorState = {
|
|
74
|
-
hoverZone: null,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
render() {
|
|
78
|
-
const { hoverZone } = this.state;
|
|
79
|
-
const { scale = 3, selectedZone, theme = 'midnight' } = this.props;
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div
|
|
83
|
-
ref={this.ref}
|
|
84
|
-
style={{
|
|
85
|
-
width: `${32 * scale}px`,
|
|
86
|
-
height: `${32 * scale}px`,
|
|
87
|
-
position: 'relative',
|
|
88
|
-
}}
|
|
89
|
-
>
|
|
90
|
-
<Image
|
|
91
|
-
src={resolveAsset(`body_zones.base_${theme}.png`)}
|
|
92
|
-
onClick={() => {
|
|
93
|
-
const onClick = this.props.onClick;
|
|
94
|
-
if (onClick && this.state.hoverZone) {
|
|
95
|
-
onClick(this.state.hoverZone);
|
|
96
|
-
}
|
|
97
|
-
}}
|
|
98
|
-
onMouseMove={(event) => {
|
|
99
|
-
if (!this.props.onClick) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const rect = this.ref.current?.getBoundingClientRect();
|
|
104
|
-
if (!rect) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const x = event.clientX - rect.left;
|
|
109
|
-
const y = 32 * scale - (event.clientY - rect.top);
|
|
110
|
-
|
|
111
|
-
this.setState({
|
|
112
|
-
hoverZone: bodyZonePixelToZone(x / scale, y / scale),
|
|
113
|
-
});
|
|
114
|
-
}}
|
|
115
|
-
style={{
|
|
116
|
-
position: 'absolute',
|
|
117
|
-
width: `${32 * scale}px`,
|
|
118
|
-
height: `${32 * scale}px`,
|
|
119
|
-
}}
|
|
120
|
-
/>
|
|
121
|
-
|
|
122
|
-
{selectedZone && (
|
|
123
|
-
<Image
|
|
124
|
-
src={resolveAsset(`body_zones.${selectedZone}.png`)}
|
|
125
|
-
style={{
|
|
126
|
-
pointerEvents: 'none',
|
|
127
|
-
position: 'absolute',
|
|
128
|
-
width: `${32 * scale}px`,
|
|
129
|
-
height: `${32 * scale}px`,
|
|
130
|
-
}}
|
|
131
|
-
/>
|
|
132
|
-
)}
|
|
133
|
-
|
|
134
|
-
{hoverZone && hoverZone !== selectedZone && (
|
|
135
|
-
<Image
|
|
136
|
-
src={resolveAsset(`body_zones.${hoverZone}.png`)}
|
|
137
|
-
style={{
|
|
138
|
-
opacity: '0.5',
|
|
139
|
-
pointerEvents: 'none',
|
|
140
|
-
position: 'absolute',
|
|
141
|
-
width: `${32 * scale}px`,
|
|
142
|
-
height: `${32 * scale}px`,
|
|
143
|
-
}}
|
|
144
|
-
/>
|
|
145
|
-
)}
|
|
146
|
-
</div>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
}
|
package/lib/components/Box.tsx
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createElement,
|
|
3
|
-
CSSProperties,
|
|
4
|
-
KeyboardEventHandler,
|
|
5
|
-
MouseEventHandler,
|
|
6
|
-
ReactNode,
|
|
7
|
-
UIEventHandler,
|
|
8
|
-
} from 'react';
|
|
9
|
-
|
|
10
|
-
import { CSS_COLORS } from '../common/constants';
|
|
11
|
-
import { BooleanLike, classes } from '../common/react';
|
|
12
|
-
|
|
13
|
-
type BooleanProps = Partial<Record<keyof typeof booleanStyleMap, boolean>>;
|
|
14
|
-
type StringProps = Partial<
|
|
15
|
-
Record<keyof typeof stringStyleMap, string | BooleanLike>
|
|
16
|
-
>;
|
|
17
|
-
|
|
18
|
-
export type EventHandlers = Partial<{
|
|
19
|
-
onClick: MouseEventHandler<HTMLDivElement>;
|
|
20
|
-
onContextMenu: MouseEventHandler<HTMLDivElement>;
|
|
21
|
-
onDoubleClick: MouseEventHandler<HTMLDivElement>;
|
|
22
|
-
onKeyDown: KeyboardEventHandler<HTMLDivElement>;
|
|
23
|
-
onKeyUp: KeyboardEventHandler<HTMLDivElement>;
|
|
24
|
-
onMouseDown: MouseEventHandler<HTMLDivElement>;
|
|
25
|
-
onMouseMove: MouseEventHandler<HTMLDivElement>;
|
|
26
|
-
onMouseOver: MouseEventHandler<HTMLDivElement>;
|
|
27
|
-
onMouseUp: MouseEventHandler<HTMLDivElement>;
|
|
28
|
-
onScroll: UIEventHandler<HTMLDivElement>;
|
|
29
|
-
}>;
|
|
30
|
-
|
|
31
|
-
export type BoxProps = Partial<{
|
|
32
|
-
as: string;
|
|
33
|
-
children: ReactNode;
|
|
34
|
-
className: string | BooleanLike;
|
|
35
|
-
style: CSSProperties;
|
|
36
|
-
}> &
|
|
37
|
-
BooleanProps &
|
|
38
|
-
StringProps &
|
|
39
|
-
EventHandlers;
|
|
40
|
-
|
|
41
|
-
// Don't you dare put this elsewhere
|
|
42
|
-
type DangerDoNotUse = {
|
|
43
|
-
dangerouslySetInnerHTML?: {
|
|
44
|
-
__html: any;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Coverts our rem-like spacing unit into a CSS unit.
|
|
50
|
-
*/
|
|
51
|
-
export function unit(value: unknown) {
|
|
52
|
-
if (typeof value === 'string') {
|
|
53
|
-
// Transparently convert pixels into rem units
|
|
54
|
-
if (value.endsWith('px')) {
|
|
55
|
-
return parseFloat(value) / 12 + 'rem';
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
if (typeof value === 'number') {
|
|
60
|
-
return value + 'rem';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Same as `unit`, but half the size for integers numbers.
|
|
66
|
-
*/
|
|
67
|
-
export function halfUnit(value: unknown): string | undefined {
|
|
68
|
-
if (typeof value === 'string') {
|
|
69
|
-
return unit(value);
|
|
70
|
-
}
|
|
71
|
-
if (typeof value === 'number') {
|
|
72
|
-
return unit(value * 0.5);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function isColorCode(str: unknown): boolean {
|
|
77
|
-
return !isColorClass(str);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function isColorClass(str: unknown): boolean {
|
|
81
|
-
return typeof str === 'string' && CSS_COLORS.includes(str as any);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const mapRawPropTo = (attrName) => (style, value) => {
|
|
85
|
-
if (typeof value === 'number' || typeof value === 'string') {
|
|
86
|
-
style[attrName] = value;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const mapUnitPropTo = (attrName, unit) => (style, value) => {
|
|
91
|
-
if (typeof value === 'number' || typeof value === 'string') {
|
|
92
|
-
style[attrName] = unit(value);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const mapBooleanPropTo = (attrName, attrValue) => (style, value) => {
|
|
97
|
-
if (value) {
|
|
98
|
-
style[attrName] = attrValue;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const mapDirectionalUnitPropTo = (attrName, unit, dirs) => (style, value) => {
|
|
103
|
-
if (typeof value === 'number' || typeof value === 'string') {
|
|
104
|
-
for (let i = 0; i < dirs.length; i++) {
|
|
105
|
-
style[attrName + '-' + dirs[i]] = unit(value);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const mapColorPropTo = (attrName) => (style, value) => {
|
|
111
|
-
if (isColorCode(value)) {
|
|
112
|
-
style[attrName] = value;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// String / number props
|
|
117
|
-
const stringStyleMap = {
|
|
118
|
-
align: mapRawPropTo('textAlign'),
|
|
119
|
-
bottom: mapUnitPropTo('bottom', unit),
|
|
120
|
-
fontFamily: mapRawPropTo('fontFamily'),
|
|
121
|
-
fontSize: mapUnitPropTo('fontSize', unit),
|
|
122
|
-
fontWeight: mapRawPropTo('fontWeight'),
|
|
123
|
-
height: mapUnitPropTo('height', unit),
|
|
124
|
-
left: mapUnitPropTo('left', unit),
|
|
125
|
-
maxHeight: mapUnitPropTo('maxHeight', unit),
|
|
126
|
-
maxWidth: mapUnitPropTo('maxWidth', unit),
|
|
127
|
-
minHeight: mapUnitPropTo('minHeight', unit),
|
|
128
|
-
minWidth: mapUnitPropTo('minWidth', unit),
|
|
129
|
-
opacity: mapRawPropTo('opacity'),
|
|
130
|
-
overflow: mapRawPropTo('overflow'),
|
|
131
|
-
overflowX: mapRawPropTo('overflowX'),
|
|
132
|
-
overflowY: mapRawPropTo('overflowY'),
|
|
133
|
-
position: mapRawPropTo('position'),
|
|
134
|
-
right: mapUnitPropTo('right', unit),
|
|
135
|
-
textAlign: mapRawPropTo('textAlign'),
|
|
136
|
-
top: mapUnitPropTo('top', unit),
|
|
137
|
-
verticalAlign: mapRawPropTo('verticalAlign'),
|
|
138
|
-
width: mapUnitPropTo('width', unit),
|
|
139
|
-
|
|
140
|
-
lineHeight: (style, value) => {
|
|
141
|
-
if (typeof value === 'number') {
|
|
142
|
-
style['lineHeight'] = value;
|
|
143
|
-
} else if (typeof value === 'string') {
|
|
144
|
-
style['lineHeight'] = unit(value);
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
// Margin
|
|
148
|
-
m: mapDirectionalUnitPropTo('margin', halfUnit, [
|
|
149
|
-
'Top',
|
|
150
|
-
'Bottom',
|
|
151
|
-
'Left',
|
|
152
|
-
'Right',
|
|
153
|
-
]),
|
|
154
|
-
mb: mapUnitPropTo('marginBottom', halfUnit),
|
|
155
|
-
ml: mapUnitPropTo('marginLeft', halfUnit),
|
|
156
|
-
mr: mapUnitPropTo('marginRight', halfUnit),
|
|
157
|
-
mt: mapUnitPropTo('marginTop', halfUnit),
|
|
158
|
-
mx: mapDirectionalUnitPropTo('margin', halfUnit, ['Left', 'Right']),
|
|
159
|
-
my: mapDirectionalUnitPropTo('margin', halfUnit, ['Top', 'Bottom']),
|
|
160
|
-
// Padding
|
|
161
|
-
p: mapDirectionalUnitPropTo('padding', halfUnit, [
|
|
162
|
-
'Top',
|
|
163
|
-
'Bottom',
|
|
164
|
-
'Left',
|
|
165
|
-
'Right',
|
|
166
|
-
]),
|
|
167
|
-
pb: mapUnitPropTo('paddingBottom', halfUnit),
|
|
168
|
-
pl: mapUnitPropTo('paddingLeft', halfUnit),
|
|
169
|
-
pr: mapUnitPropTo('paddingRight', halfUnit),
|
|
170
|
-
pt: mapUnitPropTo('paddingTop', halfUnit),
|
|
171
|
-
px: mapDirectionalUnitPropTo('padding', halfUnit, ['Left', 'Right']),
|
|
172
|
-
py: mapDirectionalUnitPropTo('padding', halfUnit, ['Top', 'Bottom']),
|
|
173
|
-
// Color props
|
|
174
|
-
color: mapColorPropTo('color'),
|
|
175
|
-
textColor: mapColorPropTo('color'),
|
|
176
|
-
backgroundColor: mapColorPropTo('backgroundColor'),
|
|
177
|
-
} as const;
|
|
178
|
-
|
|
179
|
-
// Boolean props
|
|
180
|
-
const booleanStyleMap = {
|
|
181
|
-
bold: mapBooleanPropTo('fontWeight', 'bold'),
|
|
182
|
-
fillPositionedParent: (style, value) => {
|
|
183
|
-
if (value) {
|
|
184
|
-
style['position'] = 'absolute';
|
|
185
|
-
style['top'] = 0;
|
|
186
|
-
style['bottom'] = 0;
|
|
187
|
-
style['left'] = 0;
|
|
188
|
-
style['right'] = 0;
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
inline: mapBooleanPropTo('display', 'inline-block'),
|
|
192
|
-
italic: mapBooleanPropTo('fontStyle', 'italic'),
|
|
193
|
-
nowrap: mapBooleanPropTo('whiteSpace', 'nowrap'),
|
|
194
|
-
preserveWhitespace: mapBooleanPropTo('whiteSpace', 'pre-wrap'),
|
|
195
|
-
} as const;
|
|
196
|
-
|
|
197
|
-
export function computeBoxProps(props): Record<string, any> {
|
|
198
|
-
const computedProps: Record<string, any> = {};
|
|
199
|
-
const computedStyles: Record<string, string | number> = {};
|
|
200
|
-
|
|
201
|
-
// Compute props
|
|
202
|
-
for (const propName of Object.keys(props)) {
|
|
203
|
-
if (propName === 'style') {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const propValue = props[propName];
|
|
208
|
-
|
|
209
|
-
const mapPropToStyle =
|
|
210
|
-
stringStyleMap[propName] || booleanStyleMap[propName];
|
|
211
|
-
|
|
212
|
-
if (mapPropToStyle) {
|
|
213
|
-
mapPropToStyle(computedStyles, propValue);
|
|
214
|
-
} else {
|
|
215
|
-
computedProps[propName] = propValue;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Merge computed styles and any directly provided styles
|
|
220
|
-
computedProps.style = { ...computedStyles, ...props.style };
|
|
221
|
-
|
|
222
|
-
return computedProps;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export function computeBoxClassName(props: BoxProps): string {
|
|
226
|
-
const color = props.textColor || props.color;
|
|
227
|
-
const backgroundColor = props.backgroundColor;
|
|
228
|
-
return classes([
|
|
229
|
-
isColorClass(color) && 'color-' + color,
|
|
230
|
-
isColorClass(backgroundColor) && 'color-bg-' + backgroundColor,
|
|
231
|
-
]);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export function Box(props: BoxProps & DangerDoNotUse) {
|
|
235
|
-
const { as = 'div', className, children, ...rest } = props;
|
|
236
|
-
|
|
237
|
-
// Compute class name and styles
|
|
238
|
-
const computedClassName = className
|
|
239
|
-
? `${className} ${computeBoxClassName(rest)}`
|
|
240
|
-
: computeBoxClassName(rest);
|
|
241
|
-
const computedProps = computeBoxProps(rest);
|
|
242
|
-
|
|
243
|
-
// Render the component
|
|
244
|
-
return createElement(
|
|
245
|
-
typeof as === 'string' ? as : 'div',
|
|
246
|
-
{
|
|
247
|
-
...computedProps,
|
|
248
|
-
className: computedClassName,
|
|
249
|
-
},
|
|
250
|
-
children,
|
|
251
|
-
);
|
|
252
|
-
}
|