Init rebase to Svelte and TS

This commit is contained in:
2026-02-08 10:42:58 +01:00
committed by ChaosMaker
parent 1af139201d
commit 4428cc7e8a
61 changed files with 12624 additions and 13 deletions
+54
View File
@@ -0,0 +1,54 @@
<script lang="ts">
import '../app.css';
import favicon from '$lib/assets/favicon.svg';
import { onMount, type Snippet } from 'svelte';
import { theme } from '$lib/stores/theme';
let { children }: { children: Snippet } = $props();
let bg1: string | null;
let bg2: string | null;
onMount(() => {
const style = window.getComputedStyle(document.documentElement);
bg1 = style.getPropertyValue('--dots-bg-1');
bg2 = style.getPropertyValue('--dots-bg-2');
if (bg2 && bg1) {
window.CSS.registerProperty({
name: '--dots-bg-2',
syntax: '<color>',
inherits: true,
initialValue: bg2
});
window.CSS.registerProperty({
name: '--dots-bg-1',
syntax: '<color>',
inherits: true,
initialValue: bg1
});
}
});
</script>
<svelte:head>
<link rel="icon" href={favicon} />
</svelte:head>
<main
class="text-text m-auto flex min-h-dvh w-full flex-col items-center justify-center overflow-hidden bg-dots-bg bg-size-[20px_20px]"
class:dark={$theme === 'dark'}
class:light={$theme === 'light'}
>
{@render children()}
</main>
<style>
main {
transition:
--dots-bg-2 0.2s ease-in,
--dots-bg-1 0.2s ease-in;
}
</style>
+166
View File
@@ -0,0 +1,166 @@
<script lang="ts">
import TerminalModule from '../modules/Terminal.svelte';
import { Terminal, type PrintData, type TermInitArgs } from '$lib/stores/terminal';
import type { User } from '$lib/stores/bash/bash';
import { onMount } from 'svelte';
import Settings from '../modules/Settings.svelte';
import Loading from '../modules/Loading.svelte';
import type { TreeNode } from '$lib/stores/bash/fs';
import Input from '../modules/terminal/Input.svelte';
import Cursor from '../modules/terminal/Cursor.svelte';
//let terminalMode =
function jsonToTreeNode(data: any): TreeNode {
return {
name: data.Name,
type: data.Type,
readonly: data.ReadOnly,
interactible: data.Interactible,
func: data.Func,
children: data.Children ? data.Children.map((child: any) => jsonToTreeNode(child)) : [],
content: data.Content,
link: data.Link || [],
permission: {
user: {
r: data.Permission[0]?.Read,
w: data.Permission[0]?.Write,
x: data.Permission[0]?.Exec
},
group: {
r: data.Permission[1]?.Read,
w: data.Permission[1]?.Write,
x: data.Permission[1]?.Exec
},
other: {
r: data.Permission[2]?.Read,
w: data.Permission[2]?.Write,
x: data.Permission[2]?.Exec
}
},
owner: data.Owner,
group: data.Group,
modtime: new Date(data.Mtime)
};
}
async function fetchFileSystem(path: string): Promise<any> {
const response = await fetch(path);
if (!response.ok) throw new Error('Failed to fetch the file system json');
const data = await response.json();
const node: TreeNode = jsonToTreeNode(data);
return node;
}
let callbackInit = {
print: (data: any) => {
console.log('print callback executed');
print(data);
}
};
let testUser: User = {
username: 'kamil',
passwd: '123',
uid: 0,
gid: 0,
home: '/home/kamil',
history: []
};
let terminal: Terminal;
let username: string = $state(testUser.username);
let cwd: string = $state(testUser.home);
let isInitializing = $state(true);
onMount(async () => {
try {
let fsJson = await fetchFileSystem('/src/lib/assets/fs/fs.json');
let args: TermInitArgs = {
bash: {
user: testUser,
fs: fsJson
}
};
terminal = new Terminal(args);
terminal.registerCallbacks(callbackInit);
username = terminal.getUser().username;
cwd = terminal.getCwd();
} catch (error) {
console.error('Failed to initialize terminal:', error);
} finally {
updateTerminal();
isInitializing = false;
}
});
function updateTerminal() {
username = terminal!.getUser().username;
cwd = terminal!.getCwd();
}
let terminalComponent = $state<any>();
let inputComponent = $state<any>();
function focusInput() {
console.log('focus');
inputComponent.focus();
}
function blurInput() {
console.log('blur');
inputComponent.blur();
}
function clearInput() {
inputComponent.value = '';
}
function print(data: PrintData): void {
if (isInitializing) {
console.error('Terminal is initializing! Skipping Print');
return;
}
terminalComponent.addComponent(Cursor, {
path: data.path,
output: data.output
});
updateTerminal();
}
function testAction() {
if (!terminal || isInitializing) {
console.error('Terminal is initializing!');
return;
}
terminal.executeCommand('cd ~/.config');
}
</script>
<Settings></Settings>
{#if !isInitializing}
<div class="h-dvh w-full p-24">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div onclick={() => focusInput()}>
<TerminalModule bind:this={terminalComponent} {username} {cwd}>
<Input {cwd} bind:this={inputComponent} />
</TerminalModule>
<button title="" onclick={() => testAction()}>Test Action</button>
</div>
</div>
{:else}
<Loading></Loading>
{/if}
<style>
</style>
View File
+13
View File
@@ -0,0 +1,13 @@
import { page } from '@vitest/browser/context';
import { describe, expect, it } from 'vitest';
import { render } from 'vitest-browser-svelte';
import Page from './+page.svelte';
describe('/+page.svelte', () => {
it('should render h1', async () => {
render(Page);
const heading = page.getByRole('heading', { level: 1 });
await expect.element(heading).toBeInTheDocument();
});
});
+50
View File
@@ -0,0 +1,50 @@
<script lang="ts">
import '../../app.css';
import favicon from '$lib/assets/favicon.svg';
import type { Snippet } from 'svelte';
import { BookA, ChartLine, ChartNoAxesColumn, FolderArchive, Plus } from '@lucide/svelte';
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
let { children }: { children: Snippet } = $props();
</script>
<svelte:head>
<link rel="icon" href={favicon} />
</svelte:head>
<div class="flex h-dvh w-full flex-row text-text-dark light:text-text-light">
<div class="flex h-full w-fit flex-col items-center bg-bg-dark light:bg-bg-light">
<img class="m-3 mb-8" alt="Logo" src={favicon} height="32" width="32" />
<form class="flex h-full w-fit flex-col items-center gap-3">
<label
class="m-0 mb-4 flex size-12 items-center justify-center rounded-xl bg-bg-lighter-dark shadow-subtle hover:text-primary-hover-dark has-checked:text-primary-dark has-checked:hover:text-primary-hover-dark light:bg-bg-light-light light:hover:text-primary-hover-light light:has-checked:text-primary-light light:has-checked:hover:text-primary-hover-light"
>
<input name="langs" type="radio" class="hidden" id="pl" autocomplete="off" />
<Plus strokeWidth={1} />
</label>
<SidebarButton checked path="/panel/projects">
<FolderArchive strokeWidth={1} />
</SidebarButton>
<SidebarButton path="/panel/langs">
<BookA strokeWidth={1} />
</SidebarButton>
<SidebarButton path="/panel/metrics">
<ChartLine strokeWidth={1} />
</SidebarButton>
<SidebarButton path="/panel/stats">
<ChartNoAxesColumn strokeWidth={1} />
</SidebarButton>
</form>
</div>
<div class="flex w-full grow">
{@render children()}
</div>
</div>
<style>
main {
transition:
--dots-bg-2 0.2s ease-in,
--dots-bg-1 0.2s ease-in;
}
</style>
View File
+19
View File
@@ -0,0 +1,19 @@
<script lang="ts">
import LangModule from '../../../modules/panel/LangModule.svelte';
import plFlag from '$lib/assets/plFlag.svg';
import enFlag from '$lib/assets/enFlag.svg';
import deFlag from '$lib/assets/deFlag.svg';
import frFlag from '$lib/assets/frFlag.svg';
import jaFlag from '$lib/assets/jaFlag.svg';
</script>
<div>
<form name="langs" class="m-10 flex flex-col gap-4">
<LangModule checked langName="Polish" icon={plFlag} />
<LangModule checked langName="English" icon={enFlag} />
<LangModule checked langName="German" icon={deFlag} />
<LangModule langName="Japanese" icon={jaFlag} />
<LangModule langName="French" icon={frFlag} />
</form>
<div></div>
</div>
+1
View File
@@ -0,0 +1 @@
METRICS
+7
View File
@@ -0,0 +1,7 @@
<script lang="ts">
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
</script>
<div class=" m-10">
<ProjectModule projectName="ProjectName" />
</div>
+1
View File
@@ -0,0 +1 @@
STATS