Skip to content

Commit

Permalink
Headless tgui-core (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsnow301 authored Nov 13, 2024
1 parent 0453b1c commit c0b1698
Show file tree
Hide file tree
Showing 109 changed files with 269 additions and 3,477 deletions.
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['dist/**', 'node_modules/**', 'pnpm-lock.yaml', 'lib/styles/**/*.d.ts'],
ignores: ['dist/**', 'node_modules/**', 'pnpm-lock.yaml'],
plugins: {
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
Expand All @@ -32,5 +32,5 @@ export default tseslint.config(
'unused-imports/no-unused-vars': 'off',
},
},
eslintCongigPrettier,
eslintCongigPrettier
);
6 changes: 3 additions & 3 deletions lib/common/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Color {
this.r - this.r * percent,
this.g - this.g * percent,
this.b - this.b * percent,
this.a,
this.a
);
}

Expand All @@ -49,7 +49,7 @@ export class Color {
return new Color(
parseInt(hex.slice(1, 3), 16),
parseInt(hex.slice(3, 5), 16),
parseInt(hex.slice(5, 7), 16),
parseInt(hex.slice(5, 7), 16)
);
}

Expand All @@ -61,7 +61,7 @@ export class Color {
(c2.r - c1.r) * n + c1.r,
(c2.g - c1.g) * n + c1.g,
(c2.b - c1.b) * n + c1.b,
(c2.a - c1.a) * n + c1.a,
(c2.a - c1.a) * n + c1.a
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const globalEvents = new EventEmitter();
let ignoreWindowFocus = false;

export const setupGlobalEvents = (
options: { ignoreWindowFocus?: boolean } = {},
options: { ignoreWindowFocus?: boolean } = {}
): void => {
ignoreWindowFocus = !!options.ignoreWindowFocus;
};
Expand Down
6 changes: 3 additions & 3 deletions lib/common/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SI_BASE_INDEX = SI_SYMBOLS.indexOf(' ');
export function formatSiUnit(
value: number,
minBase1000 = -SI_BASE_INDEX,
unit = '',
unit = ''
): string {
if (!isFinite(value)) {
return value.toString();
Expand Down Expand Up @@ -121,7 +121,7 @@ const SI_BASE_TEN_UNITS = [
export function formatSiBaseTenUnit(
value: number,
minBase1000 = 0,
unit = '',
unit = ''
): string {
if (!isFinite(value)) {
return 'NaN';
Expand All @@ -145,7 +145,7 @@ export function formatSiBaseTenUnit(
*/
export function formatTime(
val: number,
formatType: 'short' | 'default' = 'default',
formatType: 'short' | 'default' = 'default'
): string {
const totalSeconds = Math.floor(val / 10);
const hours = Math.floor(totalSeconds / 3600);
Expand Down
2 changes: 1 addition & 1 deletion lib/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export function fetchRetry(
url: string,
options?: RequestInit,
retryTimer: number = 1000,
retryTimer: number = 1000
): Promise<Response> {
return fetch(url, options).catch(() => {
return new Promise((resolve) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/common/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function round(num: number, dec: number): number {
(
Math.round(num * Math.pow(10, dec) + num_sign * 0.0001) /
Math.pow(10, dec)
).toFixed(dec),
).toFixed(dec)
);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ export function inRange(value: number, range: number[]): boolean {
*/
export function keyOfMatchingRange(
value: number,
ranges: Record<string, any>,
ranges: Record<string, any>
): string | undefined {
for (const rangeName of Object.keys(ranges)) {
const range = ranges[rangeName];
Expand Down
2 changes: 1 addition & 1 deletion lib/common/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function normalizeChildren<T>(children: T | T[]): T[] {
*/
export function shallowDiffers(
a: Record<string, any>,
b: Record<string, any>,
b: Record<string, any>
): boolean {
let i: string;
for (i in a) {
Expand Down
4 changes: 2 additions & 2 deletions lib/common/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
export function createSearch<TObj>(
searchText: string,
stringifier = (obj: TObj) => JSON.stringify(obj),
stringifier = (obj: TObj) => JSON.stringify(obj)
): (obj: TObj) => boolean {
const preparedSearchText = searchText.toLowerCase().trim();

Expand Down Expand Up @@ -191,7 +191,7 @@ export function decodeHtmlEntities(str: string): string {
// Basic entities
.replace(
/&(nbsp|amp|quot|lt|gt|apos);/g,
(_match, entity) => TRANSLATIONS[entity],
(_match, entity) => TRANSLATIONS[entity]
)
// Decimal entities
.replace(/&#?([0-9]+);/gi, (_match, numStr) => {
Expand Down
6 changes: 3 additions & 3 deletions lib/common/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export function debounce<F extends (...args: any[]) => any>(
fn: F,
time: number,
immediate = false,
immediate = false
): (...args: Parameters<F>) => void {
let timeout: ReturnType<typeof setTimeout> | null;
return (...args: Parameters<F>) => {
Expand All @@ -32,7 +32,7 @@ export function debounce<F extends (...args: any[]) => any>(
*/
export function throttle<F extends (...args: any[]) => any>(
fn: F,
time: number,
time: number
): (...args: Parameters<F>) => void {
let previouslyRun: number | null,
queuedToRun: ReturnType<typeof setTimeout> | null;
Expand All @@ -47,7 +47,7 @@ export function throttle<F extends (...args: any[]) => any>(
} else {
queuedToRun = setTimeout(
() => invokeFn(...args),
time - (now - (previouslyRun ?? 0)),
time - (now - (previouslyRun ?? 0))
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/common/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* ```
*/
export function getShallowTypes(
data: Record<string, any>,
data: Record<string, any>
): Record<string, any> {
const output = {};

Expand Down
6 changes: 2 additions & 4 deletions lib/components/Blink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, PropsWithChildren } from 'react';


type Props = Partial<{
/**
* The interval between blinks, in milliseconds.
Expand All @@ -11,7 +10,8 @@ type Props = Partial<{
* The time to wait before blinking again, in milliseconds.
*/
time: number;
}> & PropsWithChildren;
}> &
PropsWithChildren;

type State = {
hidden: boolean;
Expand All @@ -20,8 +20,6 @@ type State = {
const DEFAULT_BLINKING_INTERVAL = 1000;
const DEFAULT_BLINKING_TIME = 1000;



export class Blink extends Component<Props, State> {
interval: NodeJS.Timeout;
timer: NodeJS.Timeout;
Expand Down
3 changes: 1 addition & 2 deletions lib/components/BlockQuote.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { classes } from '../common/react';
import styles from '../styles/components/BlockQuote.module.scss';
import { Box, BoxProps } from './Box';

export function BlockQuote(props: BoxProps) {
const { className, ...rest } = props;

return <Box className={classes([styles.blockQuote, className])} {...rest} />;
return <Box className={classes(['BlockQuote', className])} {...rest} />;
}
2 changes: 1 addition & 1 deletion lib/components/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ export function Box(props: BoxProps & DangerDoNotUse) {
...computedProps,
className: computedClassName,
},
children,
children
);
}
40 changes: 22 additions & 18 deletions lib/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {

import { isEscape, KEY } from '../common/keys';
import { BooleanLike, classes } from '../common/react';
import styles from '../styles/components/Button.module.scss';
import { Box, BoxProps, computeBoxClassName, computeBoxProps } from './Box';
import { Icon } from './Icon';
import { Tooltip } from './Tooltip';
Expand Down Expand Up @@ -57,7 +56,7 @@ type Props = Partial<{
/** Icon rotation */
iconRotation: number;
/** Icon size */
iconSize: number
iconSize: number;
/** Makes the icon spin */
iconSpin: BooleanLike;
/** Called when element is clicked */
Expand Down Expand Up @@ -106,19 +105,20 @@ export function Button(props: Props) {
let buttonContent = (
<div
className={classes([
styles.button,
fluid && styles.fluid,
disabled && styles.disabled,
selected && styles.selected,
circular && styles.circular,
compact && styles.compact,
verticalAlignContent && styles.flex,
verticalAlignContent && fluid && styles.flex__fluid,
'Button',
fluid && 'Button--fluid',
disabled && 'Button--disabled',
selected && 'Button--selected',
circular && 'Button--circular',
compact && 'Button--compact',
iconPosition && 'Button--iconPosition--' + iconPosition,
verticalAlignContent && 'Button--flex',
verticalAlignContent && fluid && 'Button--flex--fluid',
verticalAlignContent &&
styles['verticalAlignContent__' + verticalAlignContent],
'Button--verticalAlignContent--' + verticalAlignContent,
color && typeof color === 'string'
? styles['color__' + color]
: styles['color__default'],
? 'Button--color--' + color
: 'Button--color--default',
className,
computeBoxClassName(rest),
])}
Expand Down Expand Up @@ -149,7 +149,7 @@ export function Button(props: Props) {
}}
{...computeBoxProps(rest)}
>
<div className={styles.content}>
<div className="Button__content">
{icon && iconPosition !== 'right' && (
<Icon
mr={toDisplay ? 1 : 0}
Expand All @@ -164,7 +164,10 @@ export function Button(props: Props) {
toDisplay
) : (
<span
className={classes([styles.ellipsis, icon && styles.textMargin])}
className={classes([
'Button--ellipsis',
icon && 'Button__textMargin',
])}
>
{toDisplay}
</span>
Expand Down Expand Up @@ -328,9 +331,10 @@ function ButtonInput(props: InputProps) {
let buttonContent = (
<Box
className={classes([
styles.button,
fluid && styles.fluid,
styles['color__' + color],
'Button',
fluid && 'Button--fluid',
disabled && 'Button--disabled',
'Button--color--' + color,
])}
{...rest}
onClick={() => setInInput(true)}
Expand Down
7 changes: 1 addition & 6 deletions lib/components/ColorBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ReactNode } from 'react';

import { classes } from '../common/react';
import styles from '../styles/components/ColorBox.module.scss';
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';

type Props = {
Expand All @@ -16,11 +15,7 @@ export function ColorBox(props: Props) {

return (
<div
className={classes([
styles.colorBox,
className,
computeBoxClassName(rest),
])}
className={classes(['ColorBox', className, computeBoxClassName(rest)])}
{...computeBoxProps(rest)}
>
{content || ''}
Expand Down
15 changes: 7 additions & 8 deletions lib/components/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import styles from '../styles/components/Dialog.module.scss';
import { Box } from './Box';
import { Button } from './Button';

Expand All @@ -13,10 +12,10 @@ type DialogProps = {
export function Dialog(props: DialogProps) {
const { title, onClose, children, width, height } = props;
return (
<div className={styles.dialog}>
<Box className={styles.content} width={width || '370px'} height={height}>
<div className={styles.header}>
<div className={styles.title}>{title}</div>
<div className="Dialog">
<Box className="Dialog__content" width={width || '370px'} height={height}>
<div className="Dialog__header">
<div className="Dialog__title">{title}</div>
<Box mr={2}>
<Button
mr="-3px"
Expand Down Expand Up @@ -47,7 +46,7 @@ function DialogButton(props: DialogButtonProps) {
return (
<Button
onClick={onClick}
className={styles.button}
className="Dialog__button"
verticalAlignContent="middle"
>
{children}
Expand All @@ -68,10 +67,10 @@ export function UnsavedChangesDialog(props: UnsavedChangesDialogProps) {
const { documentName, onSave, onDiscard, onClose } = props;
return (
<Dialog title="Notepad" onClose={onClose}>
<div className={styles.body}>
<div className="Dialog__body">
Do you want to save changes to {documentName}?
</div>
<div className={styles.footer}>
<div className="Dialog__footer">
<DialogButton onClick={onSave}>Save</DialogButton>
<DialogButton onClick={onDiscard}>Don&apos;t Save</DialogButton>
<DialogButton onClick={onClose}>Cancel</DialogButton>
Expand Down
3 changes: 1 addition & 2 deletions lib/components/Dimmer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { classes } from '../common/react';
import styles from '../styles/components/Dimmer.module.scss';
import { Box, BoxProps } from './Box';

export function Dimmer(props: BoxProps) {
const { className, children, ...rest } = props;

return (
<Box className={classes([styles.dimmer, className])} {...rest}>
<Box className={classes(['Dimmer', className])} {...rest}>
<div className="Dimmer__inner">{children}</div>
</Box>
);
Expand Down
6 changes: 3 additions & 3 deletions lib/components/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { classes } from '../common/react';
import styles from '../styles/components/Divider.module.scss';

type Props = Partial<{
hidden: boolean;
Expand All @@ -12,8 +11,9 @@ export function Divider(props: Props) {
return (
<div
className={classes([
hidden && styles.hidden,
vertical ? styles.vertical : styles.horizontal,
'Divider',
hidden && 'Divider--hidden',
vertical ? 'Divider--vertical' : 'Divider--horizontal',
])}
/>
);
Expand Down
Loading

0 comments on commit c0b1698

Please sign in to comment.