feat(app): use components from nextjs branch

This commit is contained in:
Pihkaal
2024-05-30 15:16:52 +02:00
parent 4d1c3d958b
commit e21d337d53
24 changed files with 3078 additions and 2810 deletions

View File

@@ -1,80 +0,0 @@
import { type Cell } from "./terminal/cell";
import { theme } from "./terminal/theme";
import { type Manifest } from "./types";
export const getExtension = (path: string) => {
const parts = path.split(".");
return parts[Math.max(0, parts.length - 1)] ?? "";
};
export const DEFAULT_FILE_STYLE: Cell = {
char: "F",
foreground: theme.white,
};
export const FILE_STYLES: Record<string, Cell> = {
md: {
char: "\ue73e",
foreground: theme.blue,
},
asc: {
char: "\uf43d",
foreground: theme.yellow,
},
};
export type File = {
name: string;
path: string;
} & (
| {
type: "file";
}
| {
type: "directory";
children: Array<File>;
folded: boolean;
}
);
const sortFiles = (files: Array<File>) =>
files
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) =>
a.type === "directory" && b.type !== "directory"
? -1
: a.type !== "directory" && b.type === "directory"
? 1
: 0,
);
export const buildFileTree = (manifest: Manifest): Array<File> => {
const files: Array<File> = [];
manifest.projects.forEach(project => {
if (project.name === "pihkaal") {
project.files.forEach(file => {
files.push({
name: file,
path: file,
type: "file",
});
});
} else {
files.push({
name: project.name,
path: project.name,
type: "directory",
folded: true,
children: sortFiles(
project.files.map(file => ({
name: file,
path: `${project.name}/${file}`,
type: "file",
})),
),
});
}
});
return sortFiles(files);
};

View File

@@ -1,17 +0,0 @@
export const clamp = (v: number, min: number, max: number): number =>
Math.min(Math.max(min, v), max);
export const clamp01 = (v: number): number => clamp(v, 0, 1);
export const clamp0 = (v: number): number => clamp(v, 0, v);
export const floorAll = (...xs: Array<number>): Array<number> =>
xs.map(Math.floor);
/**
* Random int in [min, max[
*/
export const randomMinMax = (min: number, max: number): number =>
Math.round(Math.random() * (max - min - 1) + min);
export const randomSign = (): number => Math.sign(randomMinMax(0, 2) - 1);

View File

@@ -1,4 +0,0 @@
import clsx, { type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export const cn = (...values: Array<ClassValue>) => twMerge(clsx(...values));

26
src/utils/string.ts Normal file
View File

@@ -0,0 +1,26 @@
export class CharArray {
private readonly chars: string[];
constructor(fill: string, size: number) {
this.chars = fill.repeat(size).split("");
}
set(i: number, char: string | undefined) {
if (char === undefined || i < 0 || i >= this.chars.length) return;
this.chars[i] = char;
return this;
}
write(i: number, str: string) {
for (let oi = 0; oi < str.length; oi++) {
this.set(i + oi, str[oi]);
}
return this;
}
toString() {
return this.chars.join("");
}
}

View File

@@ -1,12 +0,0 @@
export const theme = {
black: "#45475a",
red: "#f38ba8",
green: "#a6e3a1",
yellow: "#f9e2af",
blue: "#89bafa",
magenta: "#f5c2e7",
cyan: "#94e2d5",
white: "#bac2de",
grey: "#585B70",
lightGrey: "#a6adc8",
};

9
src/utils/time.ts Normal file
View File

@@ -0,0 +1,9 @@
export const formatMMSS = (time: number) => {
const minutes = Math.floor(time / 60);
const seconds = Math.floor(time % 60);
const minutesString = minutes.toString().padStart(2, "0");
const secondsString = seconds.toString().padStart(2, "0");
return `${minutesString}:${secondsString}`;
};

View File

@@ -1,6 +0,0 @@
export type Manifest = {
projects: Array<{
name: string;
files: Array<string>;
}>;
};