Compare commits
2
Commits
50872d8951
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
682d03e60c | ||
|
|
97296843df |
@@ -1,3 +0,0 @@
|
|||||||
# Drizzle
|
|
||||||
# Replace with your DB credentials!
|
|
||||||
DATABASE_URL="mysql://user:password@host:port/db-name"
|
|
||||||
@@ -7,4 +7,3 @@ bun.lockb
|
|||||||
|
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
/static/
|
/static/
|
||||||
/drizzle/
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import { defineConfig } from 'drizzle-kit';
|
|
||||||
|
|
||||||
if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
schema: './src/lib/server/db/schema.ts',
|
|
||||||
dialect: 'mysql',
|
|
||||||
dbCredentials: { url: process.env.DATABASE_URL },
|
|
||||||
verbose: true,
|
|
||||||
strict: true
|
|
||||||
});
|
|
||||||
Generated
+304
-1557
File diff suppressed because it is too large
Load Diff
+4
-13
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "svelte-portfolio",
|
"name": "svelte-portfolio",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.69",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
@@ -14,11 +14,7 @@
|
|||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . && eslint .",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"test": "npm run test:e2e && npm run test:unit -- --run",
|
"test": "npm run test:e2e && npm run test:unit -- --run",
|
||||||
"test:unit": "vitest",
|
"test:unit": "vitest"
|
||||||
"db:push": "drizzle-kit push",
|
|
||||||
"db:generate": "drizzle-kit generate",
|
|
||||||
"db:migrate": "drizzle-kit migrate",
|
|
||||||
"db:studio": "drizzle-kit studio"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^1.4.0",
|
"@eslint/compat": "^1.4.0",
|
||||||
@@ -28,15 +24,12 @@
|
|||||||
"@sveltejs/kit": "^2.43.2",
|
"@sveltejs/kit": "^2.43.2",
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.2.0",
|
"@sveltejs/vite-plugin-svelte": "^6.2.0",
|
||||||
"@tailwindcss/vite": "^4.1.16",
|
"@tailwindcss/vite": "^4.1.16",
|
||||||
"@types/node": "^24",
|
"@types/node": "^22",
|
||||||
"@vitest/browser": "^3.2.4",
|
"@vitest/browser": "^3.2.4",
|
||||||
"drizzle-kit": "^0.18.1",
|
|
||||||
"drizzle-orm": "^0.45.2",
|
|
||||||
"eslint": "^9.36.0",
|
"eslint": "^9.36.0",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-svelte": "^3.12.4",
|
"eslint-plugin-svelte": "^3.12.4",
|
||||||
"globals": "^16.4.0",
|
"globals": "^16.4.0",
|
||||||
"mysql2": "^3.16.3",
|
|
||||||
"playwright": "^1.55.1",
|
"playwright": "^1.55.1",
|
||||||
"prettier": "^3.6.2",
|
"prettier": "^3.6.2",
|
||||||
"prettier-plugin-svelte": "^3.4.0",
|
"prettier-plugin-svelte": "^3.4.0",
|
||||||
@@ -51,8 +44,6 @@
|
|||||||
"vitest-browser-svelte": "^1.1.0"
|
"vitest-browser-svelte": "^1.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lucide/svelte": "^0.548.0",
|
"@lucide/svelte": "^0.548.0"
|
||||||
"gl-matrix": "^3.4.4",
|
|
||||||
"zod": "^4.3.6"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-1
@@ -8,7 +8,6 @@ declare global {
|
|||||||
// interface PageState {}
|
// interface PageState {}
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
}
|
}
|
||||||
namespace TermOS {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@@ -433,7 +433,7 @@
|
|||||||
},
|
},
|
||||||
"13": {
|
"13": {
|
||||||
"Inode": 13,
|
"Inode": 13,
|
||||||
"Name": "gornodox",
|
"Name": "kamil",
|
||||||
"Type": 16384,
|
"Type": 16384,
|
||||||
"Size": 4096,
|
"Size": 4096,
|
||||||
"Children": [
|
"Children": [
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 44 KiB |
+1
-2
@@ -1,2 +1 @@
|
|||||||
|
// place files you want to import through the `$lib` alias in this folder.
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { customType } from 'drizzle-orm/mysql-core';
|
|
||||||
|
|
||||||
export const mediumblob = customType<{
|
|
||||||
data: Buffer;
|
|
||||||
driverData: Buffer;
|
|
||||||
}>({
|
|
||||||
dataType() {
|
|
||||||
return 'MEDIUMBLOB';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const longblob = customType<{
|
|
||||||
data: Buffer;
|
|
||||||
driverData: Buffer;
|
|
||||||
}>({
|
|
||||||
dataType() {
|
|
||||||
return 'LONGBLOB';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { drizzle } from 'drizzle-orm/mysql2';
|
|
||||||
import mysql from 'mysql2/promise';
|
|
||||||
import * as schema from './schema';
|
|
||||||
import { env } from '$env/dynamic/private';
|
|
||||||
|
|
||||||
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
|
|
||||||
|
|
||||||
const client = mysql.createPool(env.DATABASE_URL);
|
|
||||||
|
|
||||||
export const db = drizzle(client, { schema, mode: 'default', logger: true });
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
import {
|
|
||||||
boolean,
|
|
||||||
char,
|
|
||||||
int,
|
|
||||||
longtext,
|
|
||||||
mysqlTable,
|
|
||||||
serial,
|
|
||||||
text,
|
|
||||||
timestamp,
|
|
||||||
tinyint,
|
|
||||||
varchar
|
|
||||||
} from 'drizzle-orm/mysql-core';
|
|
||||||
import { longblob, mediumblob } from './custom-types';
|
|
||||||
|
|
||||||
export const task = mysqlTable('task', {
|
|
||||||
id: serial('id').primaryKey(),
|
|
||||||
title: text('title').notNull(),
|
|
||||||
priority: int('priority').notNull().default(1)
|
|
||||||
});
|
|
||||||
|
|
||||||
export const config = mysqlTable('config', {
|
|
||||||
key: varchar('key', { length: 64 }).primaryKey(),
|
|
||||||
value: longtext('value').notNull()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const projects = mysqlTable('projects', {
|
|
||||||
id: tinyint('id').notNull().primaryKey().autoincrement(),
|
|
||||||
name: text('name').notNull(),
|
|
||||||
data: longtext('data', {}).notNull(),
|
|
||||||
enabled: tinyint('enabled').notNull()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const locales = mysqlTable('locales', {
|
|
||||||
code: char('code').notNull().unique(),
|
|
||||||
name: char('name').notNull(),
|
|
||||||
dictionary: longtext().notNull(),
|
|
||||||
flag: longtext('').notNull(),
|
|
||||||
enabled: tinyint('enabled').notNull()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const groups = mysqlTable('groups', {
|
|
||||||
gid: int('gid').primaryKey().autoincrement(),
|
|
||||||
name: varchar('name', { length: 32 }).notNull().unique()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const users = mysqlTable('users', {
|
|
||||||
uid: int('uid').primaryKey().autoincrement(),
|
|
||||||
username: varchar('username', { length: 32 }).notNull().unique(),
|
|
||||||
password: varchar('password', { length: 128 }).notNull(),
|
|
||||||
home: int('home').notNull(),
|
|
||||||
gid: int('gid')
|
|
||||||
.notNull()
|
|
||||||
.references(() => groups.gid),
|
|
||||||
accessible: boolean('accessible').notNull(),
|
|
||||||
face: mediumblob('face')
|
|
||||||
});
|
|
||||||
|
|
||||||
export const filesystem = mysqlTable(
|
|
||||||
'filesystem',
|
|
||||||
{
|
|
||||||
id: int('id').primaryKey().default(1),
|
|
||||||
data: longtext('data').notNull(),
|
|
||||||
checksum: varchar('checksum', { length: 32 }).notNull(),
|
|
||||||
updatedAt: timestamp('updated_at').defaultNow().onUpdateNow()
|
|
||||||
} /* ,
|
|
||||||
{
|
|
||||||
// Ensures only one row can exist
|
|
||||||
singleRow: check('single_row_check', `id = 1`)
|
|
||||||
} */
|
|
||||||
);
|
|
||||||
|
|
||||||
export const fileContents = mysqlTable('file_contents', {
|
|
||||||
guid: varchar('guid', { length: 36 }).primaryKey(),
|
|
||||||
data: longblob('data').notNull(),
|
|
||||||
mimeType: varchar('mime_type', { length: 127 }).default('text/plain')
|
|
||||||
});
|
|
||||||
|
|
||||||
export const allowList = mysqlTable('allow_list', {
|
|
||||||
ip: int('ip').notNull()
|
|
||||||
});
|
|
||||||
|
|
||||||
export type Config = typeof config.$inferSelect;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export namespace Physis {
|
|
||||||
export class Engine {}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import Vector2 from '$lib/vector';
|
|
||||||
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
|
||||||
|
|
||||||
export class AABB {
|
|
||||||
private size: Vector2 = new Vector2();
|
|
||||||
private halfSize: Vector2 = new Vector2();
|
|
||||||
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
|
||||||
|
|
||||||
constructor(min?: Vector2, max?: Vector2) {
|
|
||||||
if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min);
|
|
||||||
|
|
||||||
this.halfSize = new Vector2(this.size.mul(0.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getMin(): Vector2 {
|
|
||||||
return new Vector2(this.rigidbody.Position).sub(this.halfSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getMax(): Vector2 {
|
|
||||||
return new Vector2(this.rigidbody.Position).add(this.halfSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AABB;
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import Vector2 from '$lib/vector';
|
|
||||||
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
|
||||||
|
|
||||||
export class Box2D {
|
|
||||||
private size: Vector2 = new Vector2();
|
|
||||||
private halfSize: Vector2 = new Vector2();
|
|
||||||
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
|
||||||
|
|
||||||
constructor();
|
|
||||||
constructor(min?: Vector2, max?: Vector2) {
|
|
||||||
if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min);
|
|
||||||
|
|
||||||
this.halfSize = new Vector2(this.size.mul(0.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getMin(): Vector2 {
|
|
||||||
return new Vector2(this.rigidbody.Position).sub(this.halfSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getMax(): Vector2 {
|
|
||||||
return new Vector2(this.rigidbody.Position).add(this.halfSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getVectices(): Vector2[] {
|
|
||||||
const min: Vector2 = this.getMin;
|
|
||||||
const max: Vector2 = this.getMax;
|
|
||||||
|
|
||||||
const vertices: Vector2[] = [
|
|
||||||
new Vector2(min.x, min.y),
|
|
||||||
new Vector2(min.x, max.y),
|
|
||||||
new Vector2(max.x, min.y),
|
|
||||||
new Vector2(max.x, max.y)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (this.rigidbody.Rotation != 0.0) {
|
|
||||||
for (const vert of vertices) {
|
|
||||||
//TODO Rotate Vert around this.rigidbody.getPosition by this.rigidbody.getRotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return vertices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getRigidbody(): Rigidbody2D {
|
|
||||||
return this.rigidbody;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get getHalfSize(): Vector2 {
|
|
||||||
return this.halfSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Box2D;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import type Vector2 from '$lib/vector';
|
|
||||||
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
|
||||||
|
|
||||||
class Circle {
|
|
||||||
private radius: number = 1.0;
|
|
||||||
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
|
||||||
|
|
||||||
public get Radius(): number {
|
|
||||||
return this.radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Center(): Vector2 {
|
|
||||||
return this.rigidbody.Position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Circle;
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import Vector2 from "$lib/vector";
|
|
||||||
|
|
||||||
class Collider2D {
|
|
||||||
protected offset: Vector2 = new Vector2();
|
|
||||||
|
|
||||||
//public abstract getInnertiaTensor(mass: number): number;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import type Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
class Ray2D {
|
|
||||||
private origin: Vector2;
|
|
||||||
private direction: Vector2;
|
|
||||||
|
|
||||||
constructor(origin: Vector2, direction: Vector2) {
|
|
||||||
this.origin = origin;
|
|
||||||
this.direction = direction;
|
|
||||||
this.direction.normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Origin(): Vector2 {
|
|
||||||
return this.origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Direction(): Vector2 {
|
|
||||||
return this.direction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Ray2D;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
class RaycastResult {
|
|
||||||
private point: Vector2 = new Vector2();
|
|
||||||
private normal: Vector2 = new Vector2();
|
|
||||||
private t: number = -1;
|
|
||||||
private hit: boolean = false;
|
|
||||||
|
|
||||||
public init(point: Vector2, normal: Vector2, t: number, hit: boolean) {
|
|
||||||
this.point.set(point.x, point.y);
|
|
||||||
this.normal.set(normal.x, normal.y);
|
|
||||||
this.t = t;
|
|
||||||
this.hit = hit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static reset(result: RaycastResult) {
|
|
||||||
if (result != null) {
|
|
||||||
result.point.set(Vector2.zero.x, Vector2.zero.y);
|
|
||||||
result.normal.set(Vector2.zero.x, Vector2.zero.y);
|
|
||||||
result.t = -1;
|
|
||||||
result.hit = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default RaycastResult;
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
import Line2D from '$lib/shimagic/renderer/line2d';
|
|
||||||
import Vector2 from '$lib/vector';
|
|
||||||
import VMath from '$lib/vmath';
|
|
||||||
import AABB from '../primitives/aabb';
|
|
||||||
import Box2D from '../primitives/box2d';
|
|
||||||
import Circle from '../primitives/circle';
|
|
||||||
import type Ray2D from '../primitives/ray2d';
|
|
||||||
import RaycastResult from '../primitives/raycast_result';
|
|
||||||
|
|
||||||
class IntersectionDetector2D {
|
|
||||||
public static pointOnLine(point: Vector2, line: Line2D): boolean {
|
|
||||||
let dy: number = line.getEnd().y - line.getStart().y;
|
|
||||||
let dx: number = line.getEnd().x - line.getStart().x;
|
|
||||||
let m: number = dy / dx;
|
|
||||||
|
|
||||||
let b = line.getEnd().y - m * line.getEnd().x;
|
|
||||||
|
|
||||||
//Check the line equation
|
|
||||||
return point.y == m * point.x + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static pointInCircle(point: Vector2, circle: Circle) {
|
|
||||||
const circleCenter: Vector2 = circle.Center;
|
|
||||||
const centerToPoint: Vector2 = new Vector2(point).sub(circleCenter);
|
|
||||||
|
|
||||||
return centerToPoint.sqrLength <= circle.Radius * circle.Radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static pointInAABB(point: Vector2, aabb: AABB): boolean {
|
|
||||||
let min: Vector2 = aabb.getMin;
|
|
||||||
let max: Vector2 = aabb.getMax;
|
|
||||||
|
|
||||||
return point.x <= max.x && point.x >= min.x && point.y >= min.y && point.y <= max.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static pointInBox2D(point: Vector2, box: Box2D): boolean {
|
|
||||||
const pointLocal = new Vector2(point);
|
|
||||||
VMath.rotate(pointLocal, box.getRigidbody.Rotation, box.getRigidbody.Position);
|
|
||||||
|
|
||||||
let min: Vector2 = box.getMin;
|
|
||||||
let max: Vector2 = box.getMax;
|
|
||||||
|
|
||||||
return (
|
|
||||||
pointLocal.x <= max.x &&
|
|
||||||
pointLocal.x >= min.x &&
|
|
||||||
pointLocal.y >= min.y &&
|
|
||||||
pointLocal.y <= max.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static lineAndCircle(line: Line2D, circle: Circle): boolean {
|
|
||||||
if (this.pointInCircle(line.getStart(), circle) || this.pointInCircle(line.getEnd(), circle))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
const ab: Vector2 = new Vector2(line.getEnd()).sub(line.getStart());
|
|
||||||
|
|
||||||
const circleCenter: Vector2 = circle.Center;
|
|
||||||
const centerToLineStart: Vector2 = new Vector2(circleCenter).sub(line.getStart());
|
|
||||||
const t: number = centerToLineStart.dot(ab) / ab.dot(ab);
|
|
||||||
|
|
||||||
if (t < 0.0 || t > 1.0) return false;
|
|
||||||
|
|
||||||
const closestPoint: Vector2 = new Vector2(line.getStart()).add(ab.mul(t));
|
|
||||||
|
|
||||||
return this.pointInCircle(closestPoint, circle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static lineAndAABB(line: Line2D, box: AABB): boolean {
|
|
||||||
if (this.pointInAABB(line.getStart(), box) || this.pointInAABB(line.getEnd(), box)) return true;
|
|
||||||
|
|
||||||
let uVec: Vector2 = new Vector2(line.getEnd()).sub(line.getStart());
|
|
||||||
uVec.normalize;
|
|
||||||
|
|
||||||
uVec.x = !uVec.equals(Vector2.zero) ? 1.0 / uVec.x : 0.0;
|
|
||||||
uVec.y = !uVec.equals(Vector2.zero) ? 1.0 / uVec.y : 0.0;
|
|
||||||
|
|
||||||
const min: Vector2 = box.getMin;
|
|
||||||
min.sub(line.getStart()).mul(uVec);
|
|
||||||
const max: Vector2 = box.getMax;
|
|
||||||
max.sub(line.getStart()).mul(uVec);
|
|
||||||
|
|
||||||
const tmin: number = Math.max(Math.min(min.x, max.x), Math.min(min.y, max.y));
|
|
||||||
const tmax: number = Math.min(Math.max(min.x, max.x), Math.max(min.y, max.y));
|
|
||||||
|
|
||||||
if (tmax < 0 || tmin > tmax) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const t = tmin < 0 ? tmax : tmin;
|
|
||||||
return t > 0 && t * t < line.lengthSqr();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static lineAndBox2D(line: Line2D, box: Box2D): boolean {
|
|
||||||
const rotation: number = box.getRigidbody.Rotation;
|
|
||||||
const center: Vector2 = box.getRigidbody.Position;
|
|
||||||
const localStart: Vector2 = new Vector2(line.getStart());
|
|
||||||
const localEnd: Vector2 = new Vector2(line.getEnd());
|
|
||||||
|
|
||||||
VMath.rotate(localStart, rotation, center);
|
|
||||||
VMath.rotate(localEnd, rotation, center);
|
|
||||||
|
|
||||||
const localLine: Line2D = new Line2D(localStart, localEnd);
|
|
||||||
const aabb: AABB = new AABB(box.getMin, box.getMax);
|
|
||||||
|
|
||||||
return this.lineAndAABB(localLine, aabb);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static raycast(circle: Circle, ray: Ray2D, result: RaycastResult): boolean;
|
|
||||||
public static raycast(aabb: AABB, ray: Ray2D, result: RaycastResult): boolean;
|
|
||||||
public static raycast(box: Box2D, ray: Ray2D, result: RaycastResult): boolean;
|
|
||||||
public static raycast(
|
|
||||||
primitive: Circle | AABB | Box2D,
|
|
||||||
ray: Ray2D,
|
|
||||||
result: RaycastResult
|
|
||||||
): boolean {
|
|
||||||
if (primitive instanceof Circle) {
|
|
||||||
RaycastResult.reset(result);
|
|
||||||
|
|
||||||
const originToCircle: Vector2 = new Vector2(primitive.Center).sub(ray.Origin);
|
|
||||||
const radiusSqr: number = primitive.Radius * primitive.Radius;
|
|
||||||
const originToCircleSqr: number = originToCircle.sqrLength;
|
|
||||||
|
|
||||||
const a: number = originToCircle.dot(ray.Direction);
|
|
||||||
const bSqr: number = originToCircleSqr - a * a;
|
|
||||||
|
|
||||||
if (radiusSqr - bSqr < 0.0) return false;
|
|
||||||
|
|
||||||
const f: number = Math.sqrt(radiusSqr - bSqr);
|
|
||||||
let t: number = 0;
|
|
||||||
if (originToCircleSqr < radiusSqr) {
|
|
||||||
t = a + f;
|
|
||||||
} else {
|
|
||||||
t = a - f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
const point: Vector2 = new Vector2(ray.Origin).add(new Vector2(ray.Direction)).mul(t);
|
|
||||||
const normal: Vector2 = new Vector2(point).sub(primitive.Center);
|
|
||||||
normal.normalize();
|
|
||||||
|
|
||||||
result.init(point, normal, t, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else if (primitive instanceof AABB) {
|
|
||||||
RaycastResult.reset(result);
|
|
||||||
let uVec: Vector2 = ray.Direction;
|
|
||||||
uVec.normalize;
|
|
||||||
|
|
||||||
uVec.x = !uVec.equals(Vector2.zero) ? 1.0 / uVec.x : 0.0;
|
|
||||||
uVec.y = !uVec.equals(Vector2.zero) ? 1.0 / uVec.y : 0.0;
|
|
||||||
|
|
||||||
const min: Vector2 = primitive.getMin;
|
|
||||||
min.sub(ray.Origin).mul(uVec);
|
|
||||||
const max: Vector2 = primitive.getMax;
|
|
||||||
max.sub(ray.Origin).mul(uVec);
|
|
||||||
|
|
||||||
const tmin: number = Math.max(Math.min(min.x, max.x), Math.min(min.y, max.y));
|
|
||||||
const tmax: number = Math.min(Math.max(min.x, max.x), Math.max(min.y, max.y));
|
|
||||||
|
|
||||||
if (tmax < 0 || tmin > tmax) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const t = tmin < 0 ? tmax : tmin;
|
|
||||||
const hit: boolean = t > 0; //&& t * t < ray.Distance;
|
|
||||||
if (!hit) return false;
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
const point: Vector2 = new Vector2(ray.Origin).add(new Vector2(ray.Direction).mul(t));
|
|
||||||
const normal: Vector2 = new Vector2(ray.Origin).sub(point);
|
|
||||||
normal.normalize();
|
|
||||||
|
|
||||||
result.init(point, normal, t, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
//TODO: Box2D implementation
|
|
||||||
|
|
||||||
RaycastResult.reset(result);
|
|
||||||
|
|
||||||
const halfSize: Vector2 = primitive.getHalfSize;
|
|
||||||
|
|
||||||
const xAxis: Vector2 = new Vector2(1, 0);
|
|
||||||
const yAxis: Vector2 = new Vector2(0, 1);
|
|
||||||
VMath.rotate(xAxis, primitive.getRigidbody.Rotation, Vector2.zero);
|
|
||||||
VMath.rotate(yAxis, primitive.getRigidbody.Rotation, Vector2.zero);
|
|
||||||
|
|
||||||
const p: Vector2 = new Vector2(primitive.getRigidbody.Position).sub(ray.Origin);
|
|
||||||
const f: Vector2 = new Vector2(xAxis.dot(ray.Direction), yAxis.dot(ray.Direction));
|
|
||||||
const e: Vector2 = new Vector2(xAxis.dot(p), yAxis.dot(p));
|
|
||||||
|
|
||||||
const tArr: number[] = [0, 0, 0, 0];
|
|
||||||
if (VMath.compare(f.x, 0)) {
|
|
||||||
if (-e.x - halfSize.x > 0 || -e.x + halfSize.x < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.x = 0.00001;
|
|
||||||
tArr[0 * 2 + 0] = e.x + halfSize.x / f.x;
|
|
||||||
tArr[0 * 2 + 1] = e.x - halfSize.x / f.x;
|
|
||||||
|
|
||||||
if (VMath.compare(f.y, 0)) {
|
|
||||||
if (-e.y - halfSize.y > 0 || -e.y + halfSize.y < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.y = 0.00001;
|
|
||||||
tArr[1 * 2 + 0] = e.y + halfSize.y / f.y;
|
|
||||||
tArr[1 * 2 + 1] = e.x - halfSize.x / f.x;
|
|
||||||
|
|
||||||
const tmin: number = Math.max(Math.min(tArr[0], tArr[1]), Math.min(tArr[2], tArr[3]));
|
|
||||||
const tmax: number = Math.min(Math.max(tArr[0], tArr[1]), Math.max(tArr[2], tArr[3]));
|
|
||||||
|
|
||||||
const t = tmin < 0 ? tmax : tmin;
|
|
||||||
const hit: boolean = t > 0; //&& t * t < ray.Distance;
|
|
||||||
if (!hit) return false;
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
const point: Vector2 = new Vector2(ray.Origin).add(new Vector2(ray.Direction).mul(t));
|
|
||||||
const normal: Vector2 = new Vector2(ray.Origin).sub(point);
|
|
||||||
normal.normalize();
|
|
||||||
|
|
||||||
result.init(point, normal, t, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static circleAndLine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
class Rigidbody2D {
|
|
||||||
private position: Vector2 = new Vector2();
|
|
||||||
private rotation: number = 0.0;
|
|
||||||
|
|
||||||
public get Position(): Vector2 {
|
|
||||||
return this.position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set setPosition(position: Vector2) {
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Rotation(): number {
|
|
||||||
return this.rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set setRotation(rotation: number) {
|
|
||||||
this.rotation = rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Rigidbody2D;
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
class Line2D {
|
|
||||||
private from: Vector2;
|
|
||||||
private to: Vector2;
|
|
||||||
|
|
||||||
constructor(from: Vector2, to: Vector2) {
|
|
||||||
this.from = from;
|
|
||||||
this.to = to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getStart(): Vector2 {
|
|
||||||
return this.from;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getEnd(): Vector2 {
|
|
||||||
return this.to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public lengthSqr(): number {
|
|
||||||
return new Vector2(this.to).sub(this.from).sqrLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Line2D;
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
import type Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
private gl: WebGL2RenderingContext;
|
|
||||||
private posBuffer!: WebGLBuffer;
|
|
||||||
private program!: WebGLProgram;
|
|
||||||
private drawMode: DrawMode = DrawMode.TEX;
|
|
||||||
|
|
||||||
constructor(canvas: HTMLCanvasElement) {
|
|
||||||
let context = canvas.getContext('webgl2');
|
|
||||||
if (!context) throw new Error(`Failed to get webgl2 context from ${canvas}`);
|
|
||||||
|
|
||||||
this.gl = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async init() {
|
|
||||||
try {
|
|
||||||
const vert: WebGLShader = await this.loadShader(
|
|
||||||
this.gl,
|
|
||||||
'src/lib/shimeji/renderer/shaders/vertex_shader.vert',
|
|
||||||
this.gl.VERTEX_SHADER
|
|
||||||
);
|
|
||||||
const frag: WebGLShader = await this.loadShader(
|
|
||||||
this.gl,
|
|
||||||
'src/lib/shimeji/renderer/shaders/fragment_shader.frag',
|
|
||||||
this.gl.FRAGMENT_SHADER
|
|
||||||
);
|
|
||||||
|
|
||||||
const program = this.gl.createProgram();
|
|
||||||
this.program = program;
|
|
||||||
|
|
||||||
this.gl.attachShader(program, vert);
|
|
||||||
this.gl.attachShader(program, frag);
|
|
||||||
this.gl.linkProgram(program);
|
|
||||||
|
|
||||||
if (!this.gl.getProgramParameter(program, this.gl.LINK_STATUS)) {
|
|
||||||
console.error(this.gl.getProgramInfoLog(program));
|
|
||||||
this.gl.deleteProgram(program);
|
|
||||||
|
|
||||||
throw new Error(`Failed to link program to webgl2 context ${program}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const pos = this.gl.createBuffer();
|
|
||||||
this.posBuffer = pos;
|
|
||||||
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, pos);
|
|
||||||
this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
||||||
|
|
||||||
let resUniLoc = this.gl.getUniformLocation(program, 'u_resolution');
|
|
||||||
|
|
||||||
this.gl.clearColor(0, 0, 0, 0);
|
|
||||||
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
this.gl.useProgram(program);
|
|
||||||
this.gl.enableVertexAttribArray(0);
|
|
||||||
|
|
||||||
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, pos);
|
|
||||||
|
|
||||||
this.gl.vertexAttribPointer(0, 2, this.gl.FLOAT, false, 0, 0);
|
|
||||||
this.gl.uniform2f(resUniLoc, this.gl.canvas.width, this.gl.canvas.height);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
this.gl.VERTEX_SHADER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async loadShader(
|
|
||||||
gl: WebGL2RenderingContext,
|
|
||||||
path: string,
|
|
||||||
type: typeof gl.VERTEX_SHADER | typeof gl.FRAGMENT_SHADER
|
|
||||||
) {
|
|
||||||
const response = await fetch(path);
|
|
||||||
if (!response.ok) throw new Error(`failed to fetch the shader file ${response}`);
|
|
||||||
const data = await response.text();
|
|
||||||
|
|
||||||
const shader = gl.createShader(type);
|
|
||||||
if (!shader) throw new Error(`Failed to create the shader ${shader}`);
|
|
||||||
|
|
||||||
gl.shaderSource(shader, data);
|
|
||||||
gl.compileShader(shader);
|
|
||||||
|
|
||||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
||||||
console.error(gl.getShaderInfoLog(shader));
|
|
||||||
gl.deleteShader(shader);
|
|
||||||
|
|
||||||
throw new Error(`Failed to compile the shader ${shader}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateBounds(width: number, height: number): void {
|
|
||||||
this.gl.viewport(0, 0, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the draw mode to one of the enum values
|
|
||||||
* @param {DrawMode} mode
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
public set SetDrawMode(mode: DrawMode) {}
|
|
||||||
|
|
||||||
public Draw(pos: Vector2, size: number): void {
|
|
||||||
//this.gl.clearColor(0, 0, 0, 0);
|
|
||||||
// this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
let x1 = pos.x - size;
|
|
||||||
let x2 = pos.x + size;
|
|
||||||
let y1 = pos.y + size;
|
|
||||||
let y2 = pos.y - size;
|
|
||||||
|
|
||||||
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.posBuffer);
|
|
||||||
this.gl.bufferData(
|
|
||||||
this.gl.ARRAY_BUFFER,
|
|
||||||
new Float32Array([x1, y1, x2, y1, x2, y2, x1, y1, x1, y2, x2, y2]),
|
|
||||||
this.gl.DYNAMIC_DRAW
|
|
||||||
);
|
|
||||||
|
|
||||||
var primitiveType = this.gl.TRIANGLES;
|
|
||||||
var offset = 0;
|
|
||||||
var count = 6;
|
|
||||||
this.gl.drawArrays(primitiveType, offset, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum DrawMode {
|
|
||||||
TEX = 0,
|
|
||||||
WIRE = 1,
|
|
||||||
VERT = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Renderer;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#version 300 es
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
out vec4 color;
|
|
||||||
in vec4 v_color;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
color = vec4(1.0, 1.0, 1.0, 1.0);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#version 300 es
|
|
||||||
|
|
||||||
layout ( location = 0 ) in vec2 a_position;
|
|
||||||
uniform vec2 u_resolution;
|
|
||||||
out vec4 v_color;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec2 zeroToOne = a_position / u_resolution;
|
|
||||||
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
||||||
vec2 clipSpace = zeroToTwo - 1.0;
|
|
||||||
|
|
||||||
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
||||||
//gl_Position = vec4(a_position, 0, 1);
|
|
||||||
gl_PointSize = 5.0;
|
|
||||||
v_color = vec4(a_position.xy, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
import type Vector2 from '$lib/vector';
|
|
||||||
|
|
||||||
export namespace WebG {
|
|
||||||
export class Engine {
|
|
||||||
private _GL: WebGL2RenderingContext;
|
|
||||||
private _Program!: WebGLProgram;
|
|
||||||
private _Shaders: Array<WebGLShader> = Array<WebGLShader>();
|
|
||||||
private _DrawMode: EngineDrawMode = EngineDrawMode.TEXTURE;
|
|
||||||
private _PosBuffer!: WebGLBuffer;
|
|
||||||
|
|
||||||
constructor(gl: WebGL2RenderingContext) {
|
|
||||||
this._GL = gl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method: Loads all shaders compiles and links them
|
|
||||||
* @async
|
|
||||||
* @public
|
|
||||||
* @param config - Engine configuration
|
|
||||||
* @returns Promise<Engine> that resolver when the engine is done initializing\
|
|
||||||
*/
|
|
||||||
public static async Initialize(config: EngineConfig) {
|
|
||||||
const GL = config.canvas.getContext('webgl2');
|
|
||||||
if (!GL) throw new Error('WebGL2 not supported!');
|
|
||||||
|
|
||||||
const shaderSources: ShaderSrc[] = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const [vertSource, fragSource] = await Promise.all([
|
|
||||||
fetch(config.vertexShaderUrl).then((r) => r.text()),
|
|
||||||
fetch(config.fragmentShaderUrl).then((r) => r.text())
|
|
||||||
]);
|
|
||||||
|
|
||||||
shaderSources.push(
|
|
||||||
{ type: GL.VERTEX_SHADER, src: vertSource, url: config.vertexShaderUrl },
|
|
||||||
{ type: GL.FRAGMENT_SHADER, src: fragSource, url: config.fragmentShaderUrl }
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`${error} Filed to fetch the shaders`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ENGINE = new Engine(GL);
|
|
||||||
ENGINE._Program = GL.createProgram();
|
|
||||||
if (!ENGINE._Program) throw new Error(`Failed to create a new program ${ENGINE._Program}`);
|
|
||||||
|
|
||||||
for (const { type, src, url } of shaderSources) {
|
|
||||||
const shader = ENGINE.compileShader(type, src, url);
|
|
||||||
|
|
||||||
ENGINE._Shaders.push(shader);
|
|
||||||
|
|
||||||
GL.attachShader(ENGINE._Program, shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
ENGINE._GL.linkProgram(ENGINE._Program);
|
|
||||||
if (!GL.getProgramParameter(ENGINE._Program, GL.LINK_STATUS))
|
|
||||||
throw new Error(
|
|
||||||
`Failed to link program ${ENGINE._Program} - Logs: ${GL.getProgramInfoLog(ENGINE._Program)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const pos = GL.createBuffer();
|
|
||||||
ENGINE._PosBuffer = pos;
|
|
||||||
ENGINE._GL.bindBuffer(ENGINE._GL.ARRAY_BUFFER, pos);
|
|
||||||
|
|
||||||
GL.enableVertexAttribArray(0);
|
|
||||||
GL.bindBuffer(GL.ARRAY_BUFFER, pos);
|
|
||||||
GL.vertexAttribPointer(0, 2, GL.FLOAT, false, 0, 0);
|
|
||||||
|
|
||||||
GL.clearColor(0, 0, 0, 0);
|
|
||||||
GL.clear(GL.COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
GL.viewport(0, 0, GL.canvas.width, GL.canvas.height);
|
|
||||||
|
|
||||||
GL.useProgram(ENGINE._Program);
|
|
||||||
|
|
||||||
let resUniLoc = GL.getUniformLocation(ENGINE._Program, 'u_resolution');
|
|
||||||
GL.uniform2f(resUniLoc, GL.canvas.width, GL.canvas.height);
|
|
||||||
return ENGINE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compile a single shader from source
|
|
||||||
* @param type - WebGL Shader type (e.g., gl.VERTEX_SHADER)
|
|
||||||
* @param src - Source code in GLSL
|
|
||||||
* @param url - Source url - used for debbugging (optional)
|
|
||||||
* @returns - Compiled {WebGLShader}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
private compileShader(type: number, src: string, url?: string) {
|
|
||||||
const shader = this._GL.createShader(type);
|
|
||||||
if (!shader) throw new Error(`Failed to create a new shader of type ${type}`);
|
|
||||||
|
|
||||||
this._GL.shaderSource(shader, src);
|
|
||||||
this._GL.compileShader(shader);
|
|
||||||
|
|
||||||
if (!this._GL.getShaderParameter(shader, this._GL.COMPILE_STATUS)) {
|
|
||||||
this._GL.deleteShader(shader);
|
|
||||||
throw new Error(
|
|
||||||
`Failed to compile shader from source ${src} located at ${url || 'unknown'} - Logs: ${this._GL.getShaderInfoLog(shader)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get GL(): WebGL2RenderingContext {
|
|
||||||
return this._GL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Program(): WebGLProgram {
|
|
||||||
return this._Program;
|
|
||||||
}
|
|
||||||
|
|
||||||
public setDrawMode(mode: EngineDrawMode) {
|
|
||||||
this._DrawMode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public draw(args: DrawCallArgs) {
|
|
||||||
const positions: Array<number> = [];
|
|
||||||
for (const v of args.vertices) {
|
|
||||||
positions.push(v.x, v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._GL.bindBuffer(this._GL.ARRAY_BUFFER, this._PosBuffer);
|
|
||||||
this._GL.bufferData(this._GL.ARRAY_BUFFER, new Float32Array(positions), this._GL.STATIC_DRAW);
|
|
||||||
|
|
||||||
this._GL.drawArrays(this._DrawMode, 0, args.vertices.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
|
||||||
for (const shader of this._Shaders) {
|
|
||||||
this._GL.detachShader(this._Program, shader);
|
|
||||||
this._GL.deleteShader(shader);
|
|
||||||
}
|
|
||||||
this._GL.deleteBuffer(this._PosBuffer);
|
|
||||||
this._GL.deleteProgram(this._Program);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enum for setting the draw mode of the engine
|
|
||||||
* @enum {0} - Texture, the default form of rendering, either a texture or a color
|
|
||||||
*/
|
|
||||||
export enum EngineDrawMode {
|
|
||||||
TEXTURE = 5, //WebGL2RenderingContext.TRIANGLE_STRIP
|
|
||||||
WIREFRAME = 2, //WebGL2RenderingContext.LINES
|
|
||||||
VERTEX = 0 //WebGL2RenderingContext.POINTS
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DrawCallArgs {
|
|
||||||
vertices: Array<Vector2>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ShaderSrc {
|
|
||||||
type: number;
|
|
||||||
src: string;
|
|
||||||
url: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {Engine} class factory method dependency that passes all the nesesary data for engine initialization
|
|
||||||
* @param canvas - A {HTMLCanvasElement}
|
|
||||||
* @param vertexShaderUrl - A string url to the primary vertex shader file
|
|
||||||
* @param fragmentShaderUrl - A string utl to the primary fragment shader file
|
|
||||||
* @param attributes - Shader attributes passed into and mapped to the program
|
|
||||||
* @param uniforms - Shader uniforms passed into and mapped to the program
|
|
||||||
*/
|
|
||||||
export interface EngineConfig {
|
|
||||||
canvas: HTMLCanvasElement;
|
|
||||||
vertexShaderUrl: string;
|
|
||||||
fragmentShaderUrl: string;
|
|
||||||
attributes?: Record<string, number>;
|
|
||||||
uniforms?: Record<string, number>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { WebG } from './renderer/web_g_engine';
|
|
||||||
|
|
||||||
export namespace Shimagic {
|
|
||||||
export class Shimeji {
|
|
||||||
private WebGEngine: WebG.Engine;
|
|
||||||
//private PhysisEngine: Physis.Engine;
|
|
||||||
private size!: number;
|
|
||||||
|
|
||||||
private AnimID: number | null = null;
|
|
||||||
private pDeltaT: number = 0;
|
|
||||||
|
|
||||||
constructor(webgengine: WebG.Engine /* physis: Physis.Engine */) {
|
|
||||||
this.WebGEngine = webgengine;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method: Initializes all sub-systems like WebG & Physis aswell as initializes the Shimeji and starts its animation
|
|
||||||
* @async
|
|
||||||
* @public
|
|
||||||
* @param {ShimejiConfig} config - Shimeji configuration
|
|
||||||
* @returns {Promise<Shimeji>} that resolves when the Shimeji is done initializing
|
|
||||||
*/
|
|
||||||
public static async Initialize(config: ShimejiConfig): Promise<Shimeji> {
|
|
||||||
const webg = await WebG.Engine.Initialize(config.webG);
|
|
||||||
//const physis = await Physis.Engine.Initialize(config.physis);
|
|
||||||
|
|
||||||
const shimeji = new Shimeji(webg);
|
|
||||||
shimeji.size = config.size;
|
|
||||||
|
|
||||||
const AFrame = (delta: number) => {
|
|
||||||
shimeji.pDeltaT = delta;
|
|
||||||
shimeji.AnimID = requestAnimationFrame(shimeji._anim);
|
|
||||||
};
|
|
||||||
|
|
||||||
shimeji.AnimID = requestAnimationFrame(AFrame);
|
|
||||||
|
|
||||||
return shimeji;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _anim(delta: number) {
|
|
||||||
let dt = (delta - this.pDeltaT) / 1000;
|
|
||||||
dt = Math.min(dt, 0.05 /* * this.Physis.TIMESCALE */);
|
|
||||||
this.pDeltaT = delta;
|
|
||||||
|
|
||||||
this.UpdatePhysics(dt);
|
|
||||||
this.UpdateFrame(dt);
|
|
||||||
|
|
||||||
this.AnimID = requestAnimationFrame(this._anim);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A function called automatically every "frame" where the code for calculating the next physics frame of the Shimeji is placed
|
|
||||||
* @param delta - Automatically passed in deltaT value;
|
|
||||||
*/
|
|
||||||
private UpdatePhysics(delta: number): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A function called automatically every "frame" where the code for drawing the next frame of the Shimeji is placed
|
|
||||||
* @param delta - Automatically passed in deltaT value;
|
|
||||||
*/
|
|
||||||
private UpdateFrame(delta: number): void {}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ShimejiConfig {
|
|
||||||
sprite: string; //temp soultion to
|
|
||||||
size: number;
|
|
||||||
webG: WebG.EngineConfig;
|
|
||||||
//physis: Physis.EngineConfig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+60
-112
@@ -1,80 +1,68 @@
|
|||||||
import { Stack } from '../stack';
|
import { COMMANDS, GROUP, PASSWD, type CommandArgs, type ICommand, type Result } from './static';
|
||||||
|
import { VirtualFS } from './fs';
|
||||||
import { Terminal, type PrintData } from '../terminal/terminal';
|
import { Terminal, type PrintData } from '../terminal/terminal';
|
||||||
import {
|
import { Stack } from '../stack';
|
||||||
COMMANDS,
|
|
||||||
type CommandArgs,
|
|
||||||
type CommandResultData,
|
|
||||||
type ICommand
|
|
||||||
} from './commandRegistry';
|
|
||||||
import { GROUP, type Group } from './etc/groupData';
|
|
||||||
import { PASSWD, type User } from './etc/userData';
|
|
||||||
import { VirtualFS, type TreeNode } from './fs';
|
|
||||||
import type { KeybindInhibitor } from './keybindInhibitor';
|
|
||||||
import { ExitCode } from './metadata';
|
|
||||||
import { Process } from './process';
|
|
||||||
|
|
||||||
export enum Signal {
|
export type Permission = {
|
||||||
SIGINT,
|
r: boolean;
|
||||||
SIGKILL
|
w: boolean;
|
||||||
}
|
x: boolean;
|
||||||
|
|
||||||
export type BashInitArgs = {
|
|
||||||
io?: Terminal;
|
|
||||||
fs: Map<number, TreeNode>;
|
|
||||||
user: { username: string; password: string };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Result = {
|
export type BashInitArgs = {
|
||||||
exitCode: ExitCode;
|
stdio?: Terminal;
|
||||||
path: number; //the inode of the place that the command was executed in
|
user: User;
|
||||||
resultData?: CommandResultData;
|
fs: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TimeStamps = {
|
||||||
|
modified: Date;
|
||||||
|
changed: Date;
|
||||||
|
accessed: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Finish this
|
||||||
|
// TODO: Change into a type instead of an enum for performance (low priority)
|
||||||
|
export enum ExitCode {
|
||||||
|
SUCCESS = 0,
|
||||||
|
ERROR = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
export type User = {
|
||||||
|
username: string;
|
||||||
|
passwd: string; //HASHED PASSWORD //TODO: Make a formated type
|
||||||
|
readonly uid: number; // Normal user 1000+ System user 1-999 root - 0 //TODO: Make a formated type
|
||||||
|
readonly gid: number; // Primary group | 'Users' 1000 - Others - 1000+ root - 0 //TODO: Make a formated type
|
||||||
|
home: string; //TODO: Make a formated type
|
||||||
|
history: string[];
|
||||||
|
cwd?: number; //TODO: Make a formated type
|
||||||
|
pwd?: number; //TODO: Make a formated type
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Group = {
|
||||||
|
groupname: string;
|
||||||
|
gid: number; // Primary group 'Users' 1000 - Others - 1000+ root - 0
|
||||||
|
members: number[]; //TODO: Make a formated type UID
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Bash {
|
export class Bash {
|
||||||
private readonly vfs: VirtualFS;
|
private vfs: VirtualFS;
|
||||||
private readonly _passwd: User[];
|
private _passwd: User[];
|
||||||
private readonly _group: Group[];
|
private _instances: Stack<User>;
|
||||||
private readonly _terminal!: Terminal;
|
private _group: Group[];
|
||||||
|
private _terminal!: Terminal;
|
||||||
|
private user: User;
|
||||||
private readonly _commands: Record<string, ICommand>;
|
private readonly _commands: Record<string, ICommand>;
|
||||||
|
|
||||||
private _userInstances: Stack<User>;
|
|
||||||
|
|
||||||
private user: User;
|
|
||||||
private _process?: Process;
|
|
||||||
|
|
||||||
constructor(args: BashInitArgs) {
|
constructor(args: BashInitArgs) {
|
||||||
|
this.user = args.user;
|
||||||
this._commands = COMMANDS;
|
this._commands = COMMANDS;
|
||||||
this._passwd = PASSWD;
|
this._passwd = PASSWD;
|
||||||
this._group = GROUP;
|
this._group = GROUP;
|
||||||
this._userInstances = new Stack<User>();
|
this._terminal = args.stdio!;
|
||||||
this._terminal = args.io!;
|
this._instances = new Stack<User>();
|
||||||
|
|
||||||
const loginResult = this.userLogin(args.user.username, args.user.password);
|
this.vfs = new VirtualFS({ fs: args.fs, user: args.user });
|
||||||
if (loginResult == ExitCode.ERROR)
|
|
||||||
this._terminal.throwExeption(
|
|
||||||
`Failed to initialize bash instance - access denied for user ${args.user.username}`,
|
|
||||||
ExitCode.ERROR
|
|
||||||
);
|
|
||||||
|
|
||||||
this.user = this._userInstances.peek()!;
|
|
||||||
this.vfs = new VirtualFS({ fs: args.fs, user: this.user });
|
|
||||||
}
|
|
||||||
|
|
||||||
private _initNewUserSession(user: User): User {
|
|
||||||
if (!this._passwd.includes(user))
|
|
||||||
this._terminal.throwExeption(
|
|
||||||
`user not found under the name ${user.username}`,
|
|
||||||
ExitCode.ERROR
|
|
||||||
);
|
|
||||||
|
|
||||||
this._userInstances.push(user);
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _initNewProcess(command: ICommand, args: CommandArgs) {
|
|
||||||
this._process = new Process(this, this.user.uid, 'TEMP PROCESS NAME', command, args);
|
|
||||||
|
|
||||||
//this._terminal.isProcessActive = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _appendNewResult(inode: number, output: any, cmd: string) {
|
private _appendNewResult(inode: number, output: any, cmd: string) {
|
||||||
@@ -83,7 +71,7 @@ export class Bash {
|
|||||||
output: output,
|
output: output,
|
||||||
cmd: cmd
|
cmd: cmd
|
||||||
};
|
};
|
||||||
console.log(this.vfs.formatPath(this.vfs.getPathByInode(inode)), 'TEST TEST !@#');
|
console.log(data);
|
||||||
this._terminal.PrintOutput(data);
|
this._terminal.PrintOutput(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +85,6 @@ export class Bash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTerminal(): void {
|
|
||||||
this._terminal.clearTerminal();
|
|
||||||
}
|
|
||||||
|
|
||||||
getCwd(): number {
|
getCwd(): number {
|
||||||
return this.vfs.cwd;
|
return this.vfs.cwd;
|
||||||
}
|
}
|
||||||
@@ -117,19 +101,6 @@ export class Bash {
|
|||||||
return this.vfs;
|
return this.vfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcess(): Process | ExitCode.ERROR {
|
|
||||||
if (this._process) {
|
|
||||||
return this._process;
|
|
||||||
}
|
|
||||||
return ExitCode.ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
getProcessKeybindInhibitor(): KeybindInhibitor | null {
|
|
||||||
if (this._process) {
|
|
||||||
return this._process.getKeybindInhibitor();
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
getTerminalWidth(): number {
|
getTerminalWidth(): number {
|
||||||
return this._terminal.getTerminalWidth();
|
return this._terminal.getTerminalWidth();
|
||||||
}
|
}
|
||||||
@@ -139,38 +110,25 @@ export class Bash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasSudoPerms(uid: number): boolean {
|
hasSudoPerms(uid: number): boolean {
|
||||||
return this._group[0].members.includes(uid);
|
return this._group[1].members.includes(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeCommand(commandName: string, args: CommandArgs): Promise<Result> {
|
executeCommand(commandName: string, args: CommandArgs): void {
|
||||||
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
||||||
const command: ICommand = this._commands[commandName];
|
const command = this._commands[commandName];
|
||||||
|
|
||||||
if (!command) this.throwError(result);
|
if (!command) this.throwError(result);
|
||||||
|
|
||||||
if (command.root) {
|
if (command.root) {
|
||||||
if (this.hasSudoPerms(this.user.uid)) {
|
if (this.hasSudoPerms(this.user.uid)) {
|
||||||
await this._initNewProcess(command, args);
|
let out: Result = command.method.call(this, args);
|
||||||
if (!this._process) throw new Error('failed to init new process');
|
|
||||||
|
|
||||||
const out: Result = await this._process.getResult();
|
|
||||||
this._appendNewResult(this.getCwd(), out, this.user.history[0]);
|
this._appendNewResult(this.getCwd(), out, this.user.history[0]);
|
||||||
}
|
}
|
||||||
this.throwError(result);
|
this.throwError(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._initNewProcess(command, args);
|
let out: Result = command.method.call(this, args);
|
||||||
if (!this._process) throw new Error('failed to init new process');
|
|
||||||
|
|
||||||
const out: Result = await this._process.getResult();
|
|
||||||
console.log(out);
|
console.log(out);
|
||||||
this._appendNewResult(out.path, out.resultData?.data, this.user.history[0]);
|
this._appendNewResult(out.path, out.data?.data, this.user.history[0]);
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static testMethod() {
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throwError(result: Result): void {
|
throwError(result: Result): void {
|
||||||
@@ -182,24 +140,14 @@ export class Bash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userLogout() {
|
userLogout() {
|
||||||
this._userInstances.pop();
|
this._instances.pop();
|
||||||
if (this._userInstances.size() === 0) {
|
if (this._instances.size() === 0) {
|
||||||
//TODO: Implement system logout
|
//TODO: Implement system logout
|
||||||
} else {
|
} else {
|
||||||
//this.changeUser(this._instances.peek()!);
|
//this.changeUser(this._instances.peek()!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userLogin(username: string, passwd: string): ExitCode {
|
|
||||||
const user: User | undefined = this._passwd.find((user) => user.username === username);
|
|
||||||
|
|
||||||
if (user && user.passwd === passwd) {
|
|
||||||
this._initNewUserSession(user);
|
|
||||||
return ExitCode.SUCCESS;
|
|
||||||
}
|
|
||||||
return ExitCode.ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatBytes(bytes: number, dPoint?: number, pow: 1024 | 1000 = 1024): string {
|
formatBytes(bytes: number, dPoint?: number, pow: 1024 | 1000 = 1024): string {
|
||||||
if (!+bytes) return '0';
|
if (!+bytes) return '0';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { Bash, Result } from '../bash';
|
import { ExitCode, type Bash } from '../bash';
|
||||||
import type { CommandArgs, ICommand } from '../commandRegistry';
|
|
||||||
import { Type, type TreeNode } from '../fs';
|
import { Type, type TreeNode } from '../fs';
|
||||||
import { ExitCode } from '../metadata';
|
import type { CommandArgs, ICommand, Result } from '../static';
|
||||||
|
|
||||||
export const cmd_cd = function (this: Bash, args: CommandArgs): Result {
|
export const cmd_cd = function (this: Bash, args: CommandArgs): Result {
|
||||||
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
||||||
@@ -22,7 +21,6 @@ export const cmd_cd = function (this: Bash, args: CommandArgs): Result {
|
|||||||
|
|
||||||
if (args.args[0] === '-') {
|
if (args.args[0] === '-') {
|
||||||
[this.getFs().cwd, this.getFs().pwd] = [this.getFs().pwd, this.getFs().cwd];
|
[this.getFs().cwd, this.getFs().pwd] = [this.getFs().pwd, this.getFs().cwd];
|
||||||
|
|
||||||
result.exitCode = ExitCode.SUCCESS;
|
result.exitCode = ExitCode.SUCCESS;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { type Bash, type Result } from "../bash";
|
import { ExitCode, type Bash } from "../bash";
|
||||||
import type { CommandArgs, ICommand } from "../commandRegistry";
|
import type { CommandArgs, ICommand, Result } from "../static";
|
||||||
import { ExitCode } from "../metadata";
|
|
||||||
|
|
||||||
export const cmd_clear = function(this: Bash, args: CommandArgs): Result {
|
export const cmd_clear = function(this: Bash, args: CommandArgs): Result {
|
||||||
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
||||||
this.clearTerminal();
|
|
||||||
result.exitCode = ExitCode.SUCCESS;
|
result.exitCode = ExitCode.SUCCESS;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import type { Bash, Result } from '../bash';
|
import { Bash, ExitCode, type Permission, type TimeStamps } from '../bash';
|
||||||
import type { CommandArgs, CommandResultData, ICommand } from '../commandRegistry';
|
|
||||||
import { Type, VirtualFS, type NodePerms, type TreeNode } from '../fs';
|
import { Type, VirtualFS, type NodePerms, type TreeNode } from '../fs';
|
||||||
import { ExitCode, type Permission } from '../metadata';
|
|
||||||
import { Sort, SortNodeBy } from '../sort';
|
import { Sort, SortNodeBy } from '../sort';
|
||||||
|
import type { CommandArgs, ICommand, Result, resultData } from '../static';
|
||||||
|
|
||||||
type LsEntry = {
|
type LsEntry = {
|
||||||
inode: number | null;
|
inode: number | null;
|
||||||
@@ -40,8 +39,8 @@ const months: readonly string[] = [
|
|||||||
|
|
||||||
export const cmd_ls = function (this: Bash, args: CommandArgs): Result {
|
export const cmd_ls = function (this: Bash, args: CommandArgs): Result {
|
||||||
const Fs = this.getFs();
|
const Fs = this.getFs();
|
||||||
const resultData: CommandResultData = { cmd: 'ls', data: null, args: args };
|
const resultData: resultData = { cmd: 'ls', data: null, args: args };
|
||||||
const result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd(), resultData: resultData };
|
const result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd(), data: resultData };
|
||||||
const nodes: TreeNode[] = [];
|
const nodes: TreeNode[] = [];
|
||||||
|
|
||||||
//Check if any args contain the long flags with value and are valid flags inside the ls const
|
//Check if any args contain the long flags with value and are valid flags inside the ls const
|
||||||
@@ -72,24 +71,26 @@ export const cmd_ls = function (this: Bash, args: CommandArgs): Result {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
||||||
|
const dummysonoerror: HTMLElement = document.createElement('div');
|
||||||
const Fs: VirtualFS = this.getFs();
|
const Fs: VirtualFS = this.getFs();
|
||||||
|
|
||||||
|
|
||||||
const flagInfo = checkFlags(args.flags);
|
const flagInfo = checkFlags(args.flags);
|
||||||
const nodes: TreeNode[] = data;
|
const nodes: TreeNode[] = data;
|
||||||
let nodeIndex: number = 0;
|
let nodeIndex: number = 0;
|
||||||
|
|
||||||
const f_a: boolean = flagInfo.has('a') || flagInfo.has('all');
|
const f_a: boolean = flagInfo.has('a') || flagInfo.has('all');
|
||||||
const f_A: boolean = flagInfo.has('A') || flagInfo.has('almost-all');
|
const f_A: boolean = flagInfo.has('A') || flagInfo.has('almost-all');
|
||||||
//const f_G: boolean = flagInfo.has('G') || flagInfo.has('no-group');
|
const f_G: boolean = flagInfo.has('G') || flagInfo.has('no-group');
|
||||||
const f_h: boolean = flagInfo.has('h') || flagInfo.has('human-readable');
|
const f_h: boolean = flagInfo.has('h') || flagInfo.has('human-readable');
|
||||||
const f_r: boolean = flagInfo.has('r') || flagInfo.has('reverse');
|
const f_r: boolean = flagInfo.has('r') || flagInfo.has('reverse');
|
||||||
const f_R: boolean = flagInfo.has('R') || flagInfo.has('recursive');
|
const f_R: boolean = flagInfo.has('R') || flagInfo.has('recursive');
|
||||||
//const f_Q: boolean = flagInfo.has('Q') || flagInfo.has('quote-name');
|
const f_Q: boolean = flagInfo.has('Q') || flagInfo.has('quote-name');
|
||||||
//const f_n: boolean = flagInfo.has('n') || flagInfo.has('numeric-uid-gid');
|
const f_n: boolean = flagInfo.has('n') || flagInfo.has('numeric-uid-gid');
|
||||||
//const f_N: boolean = flagInfo.has('N') || flagInfo.has('literal');
|
const f_N: boolean = flagInfo.has('N') || flagInfo.has('literal');
|
||||||
//const f_L: boolean = flagInfo.has('L') || flagInfo.has('dereference');
|
const f_L: boolean = flagInfo.has('L') || flagInfo.has('dereference');
|
||||||
const f_i: boolean = flagInfo.has('i') || flagInfo.has('inode');
|
const f_i: boolean = flagInfo.has('i') || flagInfo.has('inode');
|
||||||
//const f_help: boolean = flagInfo.has('help');
|
const f_help: boolean = flagInfo.has('help');
|
||||||
const f_si: boolean = flagInfo.has('si');
|
const f_si: boolean = flagInfo.has('si');
|
||||||
const f_X: boolean = flagInfo.has('X');
|
const f_X: boolean = flagInfo.has('X');
|
||||||
const f_S: boolean = flagInfo.has('S');
|
const f_S: boolean = flagInfo.has('S');
|
||||||
@@ -224,7 +225,7 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
|||||||
colWidths.push(Math.max(...columns[i].map((name) => name.length)));
|
colWidths.push(Math.max(...columns[i].map((name) => name.length)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const calcWidth: number = colWidths.reduce((prev, curr) => prev + curr) + ((c-1) * 2);
|
const calcWidth: number = colWidths.reduce((prev, curr) => prev + curr) + ((c-1) * 3);
|
||||||
|
|
||||||
if(calcWidth < maxWidth) lowBound = c + 1;
|
if(calcWidth < maxWidth) lowBound = c + 1;
|
||||||
else if(calcWidth > maxWidth) highBound = c -1
|
else if(calcWidth > maxWidth) highBound = c -1
|
||||||
@@ -233,7 +234,6 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
|||||||
const wrapper: HTMLElement = document.createElement('div');
|
const wrapper: HTMLElement = document.createElement('div');
|
||||||
|
|
||||||
wrapper.style.display = 'flex';
|
wrapper.style.display = 'flex';
|
||||||
wrapper.style.columnGap = `${this.getTerminalFontSize() * 2}px`;
|
|
||||||
wrapper.style.marginBottom = `${this.getTerminalFontSize() * 2}px`;
|
wrapper.style.marginBottom = `${this.getTerminalFontSize() * 2}px`;
|
||||||
|
|
||||||
let fileIndex = 0;
|
let fileIndex = 0;
|
||||||
@@ -278,8 +278,8 @@ function isValidNodeTimestamp(value: string): value is SortNodeBy.ATIME | SortNo
|
|||||||
function parsePerms(perms: NodePerms): string {
|
function parsePerms(perms: NodePerms): string {
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
//for each key (key representing key name and p representing the key contents) of entries in perms as types keyof NodePerms and Permission
|
//for each key (key representing key name and p representing the key contents) of entries in perms as types keyof NodePerms and Permission
|
||||||
for (const [, permission] of Object.entries(perms) as [keyof NodePerms, Permission][]) {
|
for (const [key, p] of Object.entries(perms) as [keyof NodePerms, Permission][]) {
|
||||||
const perms: string = `${permission.r ? 'r' : '-'}${permission.w ? 'w' : '-'}${permission.x ? 'x' : '-'}`;
|
const perms: string = `${p.r ? 'r' : '-'}${p.w ? 'w' : '-'}${p.x ? 'x' : '-'}`;
|
||||||
parts.push(perms);
|
parts.push(perms);
|
||||||
}
|
}
|
||||||
return parts.join('');
|
return parts.join('');
|
||||||
@@ -322,6 +322,7 @@ function formatChildren(node: TreeNode): string {
|
|||||||
if (!node.children) throw new Error('children array is null on this node');
|
if (!node.children) throw new Error('children array is null on this node');
|
||||||
|
|
||||||
const c = node.children.length.toString();
|
const c = node.children.length.toString();
|
||||||
|
console.log(c, "TEST TEST");
|
||||||
return c.length > 1 ? c : ` ${c}`;
|
return c.length > 1 ? c : ` ${c}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,14 +362,26 @@ function formatName(node: TreeNode, flag: any, shouldShift: boolean) {
|
|||||||
let name: string = node.name;
|
let name: string = node.name;
|
||||||
const char: string = flag.has('Q') ? '"' : "'";
|
const char: string = flag.has('Q') ? '"' : "'";
|
||||||
|
|
||||||
if (/\s/.test(node.name)) {
|
if (/\s/.test(node.name)) name = `${char}${name}${char}`;
|
||||||
name = `${char}${name}${char}`
|
|
||||||
} else {
|
if(flag.has('p') && node.type === Type.Directory) name = `${name}/`
|
||||||
//Shift non quoted names 1 char right to align if any names in group have a quote
|
|
||||||
name = `${shouldShift ? ' ' : ''}${node.name}`;
|
if((flag.has('l') || flag.has('g') || flag.has('o'))) {
|
||||||
|
// Is the ls in long format
|
||||||
|
if (!(/\s/.test(node.name))) {
|
||||||
|
//Shift non quoted names 1 char right to align if any names in group have a quote
|
||||||
|
name = `${shouldShift ? ' ' : ''}${name}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!(/\s/.test(node.name))) {
|
||||||
|
name = ` ${name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = `${name} `;
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag.has('p') && node.type === Type.Directory ? `${name}/` : name;
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkFlags = (pFlags: string[]) => {
|
const checkFlags = (pFlags: string[]) => {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import type { ICommand } from "../static"
|
||||||
|
import { cmd_ls } from "./ls"
|
||||||
|
|
||||||
|
type LsEntry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class ls {
|
||||||
|
public const ls: ICommand = {
|
||||||
|
method: ls.cmd_ls
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import type { KeyBind } from "$lib/stores/terminal/keybindRegistry";
|
|
||||||
import { mount } from "svelte";
|
|
||||||
import { type Bash, type Result } from "../bash";
|
|
||||||
import type { CommandArgs, CommandResultData, ICommand } from "../commandRegistry";
|
|
||||||
import { ExitCode } from "../metadata";
|
|
||||||
import Login from "../../../../modules/Login.svelte";
|
|
||||||
import Loading from "../../../../modules/Loading.svelte";
|
|
||||||
|
|
||||||
export const cmd_process = function(this: Bash, args: CommandArgs): Result {
|
|
||||||
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
|
||||||
const resultData: CommandResultData = { cmd: 'ls', data: null, args: args };
|
|
||||||
|
|
||||||
result.resultData = resultData;
|
|
||||||
result.exitCode = ExitCode.SUCCESS;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
const test_keybind: KeyBind = [
|
|
||||||
{
|
|
||||||
key: 'a',
|
|
||||||
modifiers: [
|
|
||||||
'Shift'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
function test(): void {
|
|
||||||
console.log("Keybind works");
|
|
||||||
}
|
|
||||||
|
|
||||||
const keybinds: Map<KeyBind, () => any> = new Map([
|
|
||||||
[test_keybind,test]
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const testProcess: ICommand = {
|
|
||||||
method: cmd_process,
|
|
||||||
keybinds: keybinds,
|
|
||||||
flags: [] as string[],
|
|
||||||
help: 'PATH TO HELP.md',
|
|
||||||
root: false
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
export type Group = {
|
|
||||||
groupname: string;
|
|
||||||
gid: number; // Primary group 'Users' 1000 - Others - 1000+ root - 0
|
|
||||||
members: number[]; //TODO: Make a formated type UID
|
|
||||||
};
|
|
||||||
|
|
||||||
export const GROUP: Group[] = [
|
|
||||||
{
|
|
||||||
groupname: 'sudo',
|
|
||||||
gid: 69,
|
|
||||||
members: [0, 1001]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
groupname: 'users',
|
|
||||||
gid: 984,
|
|
||||||
members: [1001, 1002]
|
|
||||||
}
|
|
||||||
] as const;
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
export type User = {
|
|
||||||
username: string;
|
|
||||||
passwd: string; //HASHED PASSWORD //TODO: Make a formated type
|
|
||||||
readonly uid: number; // Normal user 1000+ System user 1-999 root - 0 //TODO: Make a formated type
|
|
||||||
readonly gid: number; // Primary group | 'Users' 1000 - Others - 1000+ root - 0 //TODO: Make a formated type
|
|
||||||
home: string; //TODO: Make a formated type
|
|
||||||
accesible: boolean;
|
|
||||||
history: string[];
|
|
||||||
cwd?: number; //TODO: Make a formated type
|
|
||||||
pwd?: number; //TODO: Make a formated type
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PASSWD: User[] = [
|
|
||||||
{
|
|
||||||
username: 'root',
|
|
||||||
passwd: '123',
|
|
||||||
uid: 0,
|
|
||||||
gid: 0,
|
|
||||||
home: '/',
|
|
||||||
accesible: false,
|
|
||||||
history: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: 'admin',
|
|
||||||
passwd: '456',
|
|
||||||
uid: 1000,
|
|
||||||
gid: 1000,
|
|
||||||
home: '/home/admin',
|
|
||||||
accesible: true,
|
|
||||||
history: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: 'user',
|
|
||||||
passwd: '789',
|
|
||||||
uid: 1001,
|
|
||||||
gid: 1000,
|
|
||||||
home: '/home/user',
|
|
||||||
accesible: true,
|
|
||||||
history: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: 'gornodox',
|
|
||||||
passwd: '000',
|
|
||||||
uid: 1002,
|
|
||||||
gid: 1000,
|
|
||||||
home: '/home/gornodox',
|
|
||||||
accesible: true,
|
|
||||||
history: []
|
|
||||||
}
|
|
||||||
];
|
|
||||||
+18
-60
@@ -1,5 +1,4 @@
|
|||||||
import type { User } from './etc/userData';
|
import type { Permission, TimeStamps, User } from './bash';
|
||||||
import type { Permission, TimeStamps } from './metadata';
|
|
||||||
|
|
||||||
export enum Type {
|
export enum Type {
|
||||||
Directory = 16384,
|
Directory = 16384,
|
||||||
@@ -7,14 +6,14 @@ export enum Type {
|
|||||||
SymbolicLink = 40960
|
SymbolicLink = 40960
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NodePermission = {
|
export type NodePerms = {
|
||||||
user: Permission;
|
user: Permission;
|
||||||
group: Permission;
|
group: Permission;
|
||||||
other: Permission;
|
other: Permission;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FsInitArgs = {
|
export type FsInitArgs = {
|
||||||
fs: Map<number, TreeNode>;
|
fs: any;
|
||||||
user: User;
|
user: User;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ export type TreeNode = {
|
|||||||
export class VirtualFS {
|
export class VirtualFS {
|
||||||
private FsTable: Map<number, TreeNode>;
|
private FsTable: Map<number, TreeNode>;
|
||||||
private rootINode: number;
|
private rootINode: number;
|
||||||
private user: User;
|
|
||||||
|
|
||||||
home: number;
|
home: number;
|
||||||
cwd: number;
|
cwd: number;
|
||||||
@@ -46,12 +44,10 @@ export class VirtualFS {
|
|||||||
|
|
||||||
constructor(args: FsInitArgs) {
|
constructor(args: FsInitArgs) {
|
||||||
this.FsTable = args.fs;
|
this.FsTable = args.fs;
|
||||||
this.user = args.user;
|
|
||||||
this.rootINode = 1;
|
this.rootINode = 1;
|
||||||
|
|
||||||
this.home = this._pathStringToINode(args.user.home);
|
this.home = this._pathStringToINode(args.user.home);
|
||||||
this.cwd = args.user.cwd ? args.user.cwd! : this.home;
|
this.cwd = args.user.cwd ? args.user.cwd : this.home;
|
||||||
this.pwd = args.user.pwd ? args.user.pwd! : this.cwd;
|
this.pwd = args.user.pwd ? args.user.pwd : this.cwd;
|
||||||
|
|
||||||
console.log(this.home);
|
console.log(this.home);
|
||||||
console.log(this.cwd);
|
console.log(this.cwd);
|
||||||
@@ -60,11 +56,10 @@ export class VirtualFS {
|
|||||||
|
|
||||||
private _iNodeToPathString(inode: number): string {
|
private _iNodeToPathString(inode: number): string {
|
||||||
const currentNode = this.FsTable.get(inode);
|
const currentNode = this.FsTable.get(inode);
|
||||||
|
|
||||||
if (!currentNode)
|
if (!currentNode)
|
||||||
throw new Error('could not find the node in the fs table - inodetopathstring');
|
throw new Error('could not find the node in the fs table - inodetopathstring');
|
||||||
|
|
||||||
if (!currentNode.parent || currentNode.inode === this.rootINode) {
|
if (!currentNode.parent) {
|
||||||
return '/';
|
return '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,63 +150,26 @@ export class VirtualFS {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public recursiveTraversalPre(
|
public recursiveTraversalPre(node: TreeNode, callback: (param: TreeNode) => void, childIndex?: number[], depthIndex?: number): void {
|
||||||
node: TreeNode,
|
if(!depthIndex) depthIndex = 0;
|
||||||
callback: (param: TreeNode) => void,
|
if(!childIndex) childIndex = [0];
|
||||||
childIndex?: number[],
|
|
||||||
depthIndex?: number
|
|
||||||
): void {
|
|
||||||
if (!depthIndex) depthIndex = 0;
|
|
||||||
if (!childIndex) childIndex = [0];
|
|
||||||
|
|
||||||
if (node.type != Type.File && node.children[childIndex[depthIndex]]) {
|
if(node.type != Type.File && node.children[childIndex[depthIndex]]) {
|
||||||
node = this.getNodeByINode(node.children[childIndex[depthIndex]]);
|
node = this.getNodeByINode(node.children[childIndex[depthIndex]]);
|
||||||
depthIndex++;
|
depthIndex++;
|
||||||
if (!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
if(!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
||||||
|
|
||||||
callback(node);
|
callback(node);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
node = this.getNodeByINode(node.parent);
|
node = this.getNodeByINode(node.parent);
|
||||||
childIndex[depthIndex] = 0;
|
childIndex[depthIndex] = 0;
|
||||||
depthIndex--;
|
depthIndex--;
|
||||||
childIndex[depthIndex]++;
|
childIndex[depthIndex]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depthIndex < 0) return;
|
if(depthIndex < 0) return;
|
||||||
|
|
||||||
this.recursiveTraversalPre(node, callback, childIndex, depthIndex);
|
this.recursiveTraversalPre(node, callback, childIndex, depthIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createNode(name: string, type: Type, path: number, user: number): void {
|
|
||||||
let children: null | number[];
|
|
||||||
|
|
||||||
const node: TreeNode = {
|
|
||||||
inode: this.FsTable.size + 1,
|
|
||||||
name: name,
|
|
||||||
type: type,
|
|
||||||
size: 4096, //TODO: Calculate the size from the content
|
|
||||||
children: [],
|
|
||||||
content: '',
|
|
||||||
link: -1,
|
|
||||||
permission: {
|
|
||||||
user: {
|
|
||||||
r: true,
|
|
||||||
w: true,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
group: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
other: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
owner: user,
|
|
||||||
group:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
import type { KeyBind, Modifier } from "../terminal/keybindRegistry";
|
|
||||||
|
|
||||||
|
|
||||||
export class KeybindInhibitor{
|
|
||||||
private _keybinds: Map<KeyBind, () => any>;
|
|
||||||
|
|
||||||
constructor(keybinds: Map<KeyBind, () => any>) {
|
|
||||||
this._keybinds = keybinds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseModifierStates(event: KeyboardEvent): Modifier[] | undefined {
|
|
||||||
const mods: Modifier[] = [];
|
|
||||||
|
|
||||||
if(event.altKey) mods.push('Alt');
|
|
||||||
if(event.ctrlKey) mods.push('Ctrl');
|
|
||||||
if(event.shiftKey) mods.push('Shift');
|
|
||||||
|
|
||||||
if(mods.length == 0) return undefined;
|
|
||||||
|
|
||||||
return mods;
|
|
||||||
}
|
|
||||||
|
|
||||||
processKeystroke(event: KeyboardEvent) {
|
|
||||||
const keybind: KeyBind = [
|
|
||||||
{
|
|
||||||
key: event.key,
|
|
||||||
modifiers: this.parseModifierStates(event)
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const out = this._keybinds.get(keybind);
|
|
||||||
if(out) out();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export type TimeStamps = {
|
|
||||||
modified: Date;
|
|
||||||
changed: Date;
|
|
||||||
accessed: Date;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Finish this
|
|
||||||
export enum ExitCode {
|
|
||||||
SUCCESS = 0,
|
|
||||||
ERROR = 1
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import type { Bash, Result } from './bash';
|
|
||||||
import type { CommandArgs, ICommand } from './commandRegistry';
|
|
||||||
import { KeybindInhibitor } from './keybindInhibitor';
|
|
||||||
import { ExitCode } from './metadata';
|
|
||||||
|
|
||||||
export class Process {
|
|
||||||
private _bash: Bash;
|
|
||||||
private _result: Result;
|
|
||||||
private _uid: number;
|
|
||||||
private _name: string;
|
|
||||||
private _initTimestamp: Date;
|
|
||||||
private _keybindInhibitor?: KeybindInhibitor;
|
|
||||||
private _abortController: AbortController;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
_bashInstance: Bash,
|
|
||||||
uid: number,
|
|
||||||
name: string,
|
|
||||||
command: ICommand,
|
|
||||||
args: CommandArgs
|
|
||||||
) {
|
|
||||||
this._bash = _bashInstance;
|
|
||||||
this._result = { exitCode: ExitCode.ERROR, path: this._bash.getCwd() };
|
|
||||||
this._uid = uid;
|
|
||||||
this._name = name;
|
|
||||||
this._initTimestamp = new Date();
|
|
||||||
this._abortController = new AbortController();
|
|
||||||
|
|
||||||
if (command.keybinds) {
|
|
||||||
this._keybindInhibitor = new KeybindInhibitor(command.keybinds);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._Run(command, _bashInstance, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKeybindInhibitor(): KeybindInhibitor | null {
|
|
||||||
if (this._keybindInhibitor) {
|
|
||||||
return this._keybindInhibitor;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sigKill(callback: () => void): ExitCode {
|
|
||||||
this._abortController.abort();
|
|
||||||
callback();
|
|
||||||
|
|
||||||
return ExitCode.SUCCESS; //Only temp, need to add ExitCode.INT
|
|
||||||
}
|
|
||||||
|
|
||||||
public getUid(): number {
|
|
||||||
return this._uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getInitTime(): Date {
|
|
||||||
return this._initTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getName(): string {
|
|
||||||
return this._name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getResult(): Promise<Result> {
|
|
||||||
return this._result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _Run(command: ICommand, bashInstance: Bash, args: CommandArgs) {
|
|
||||||
this._result = command.method.call(bashInstance, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-121
@@ -1,5 +1,6 @@
|
|||||||
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
|
||||||
import type { TreeNode } from './fs';
|
import type { TreeNode } from './fs';
|
||||||
|
import type { Bash } from './bash';
|
||||||
|
import { Posix } from './posix';
|
||||||
|
|
||||||
export enum SortNodeBy {
|
export enum SortNodeBy {
|
||||||
NAME = 'name',
|
NAME = 'name',
|
||||||
@@ -14,21 +15,17 @@ export enum SortNodeBy {
|
|||||||
|
|
||||||
export class Sort {
|
export class Sort {
|
||||||
public static nodeArraySort(
|
public static nodeArraySort(
|
||||||
|
this: Bash,
|
||||||
nodes: TreeNode[] | number[],
|
nodes: TreeNode[] | number[],
|
||||||
reverse: boolean = false,
|
reverse: boolean = false,
|
||||||
sortBy: SortNodeBy = SortNodeBy.NAME
|
sortBy: SortNodeBy = SortNodeBy.NAME
|
||||||
): TreeNode[] {
|
): TreeNode[] {
|
||||||
const Fs = FileSystem.instance;
|
if (nodes.length === 0) {console.warn('Tried to sort an empty node array!'); return [];}
|
||||||
|
|
||||||
if (nodes.length === 0) {
|
|
||||||
console.warn('Tried to sort an empty node array!');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const parsedNodes: TreeNode[] = [];
|
const parsedNodes: TreeNode[] = [];
|
||||||
|
|
||||||
if (typeof nodes[0] === 'number') {
|
if (typeof nodes[0] === 'number') {
|
||||||
for (const inode of nodes as number[]) {
|
for (const inode of nodes as number[]) {
|
||||||
const node = Fs.getNodeByInode(inode);
|
const node = this.getFs().getNodeByINode(inode);
|
||||||
parsedNodes.push(node);
|
parsedNodes.push(node);
|
||||||
}
|
}
|
||||||
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
||||||
@@ -143,116 +140,3 @@ export class Sort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Posix {
|
|
||||||
private static readonly CharTable = {
|
|
||||||
// Space and punctuation (32-47)
|
|
||||||
' ': 32,
|
|
||||||
'!': 33,
|
|
||||||
'"': 34,
|
|
||||||
'#': 35,
|
|
||||||
$: 36,
|
|
||||||
'%': 37,
|
|
||||||
'&': 38,
|
|
||||||
"'": 39,
|
|
||||||
'(': 40,
|
|
||||||
')': 41,
|
|
||||||
'*': 42,
|
|
||||||
'+': 43,
|
|
||||||
',': 44,
|
|
||||||
'-': 45,
|
|
||||||
'.': 46,
|
|
||||||
'/': 47,
|
|
||||||
|
|
||||||
// Numbers 0-9 (48-57)
|
|
||||||
'0': 48,
|
|
||||||
'1': 49,
|
|
||||||
'2': 50,
|
|
||||||
'3': 51,
|
|
||||||
'4': 52,
|
|
||||||
'5': 53,
|
|
||||||
'6': 54,
|
|
||||||
'7': 55,
|
|
||||||
'8': 56,
|
|
||||||
'9': 57,
|
|
||||||
|
|
||||||
// More punctuation (58-64)
|
|
||||||
':': 58,
|
|
||||||
';': 59,
|
|
||||||
'<': 60,
|
|
||||||
'=': 61,
|
|
||||||
'>': 62,
|
|
||||||
'?': 63,
|
|
||||||
'@': 64,
|
|
||||||
|
|
||||||
// LETTERS - INTERLEAVED AaBbCc... (65-116)
|
|
||||||
A: 65,
|
|
||||||
a: 66,
|
|
||||||
B: 67,
|
|
||||||
b: 68,
|
|
||||||
C: 69,
|
|
||||||
c: 70,
|
|
||||||
D: 71,
|
|
||||||
d: 72,
|
|
||||||
E: 73,
|
|
||||||
e: 74,
|
|
||||||
F: 75,
|
|
||||||
f: 76,
|
|
||||||
G: 77,
|
|
||||||
g: 78,
|
|
||||||
H: 79,
|
|
||||||
h: 80,
|
|
||||||
I: 81,
|
|
||||||
i: 82,
|
|
||||||
J: 83,
|
|
||||||
j: 84,
|
|
||||||
K: 85,
|
|
||||||
k: 86,
|
|
||||||
L: 87,
|
|
||||||
l: 88,
|
|
||||||
M: 89,
|
|
||||||
m: 90,
|
|
||||||
N: 91,
|
|
||||||
n: 92,
|
|
||||||
O: 93,
|
|
||||||
o: 94,
|
|
||||||
P: 95,
|
|
||||||
p: 96,
|
|
||||||
Q: 97,
|
|
||||||
q: 98,
|
|
||||||
R: 99,
|
|
||||||
r: 100,
|
|
||||||
S: 101,
|
|
||||||
s: 102,
|
|
||||||
T: 103,
|
|
||||||
t: 104,
|
|
||||||
U: 105,
|
|
||||||
u: 106,
|
|
||||||
V: 107,
|
|
||||||
v: 108,
|
|
||||||
W: 109,
|
|
||||||
w: 110,
|
|
||||||
X: 111,
|
|
||||||
x: 112,
|
|
||||||
Y: 113,
|
|
||||||
y: 114,
|
|
||||||
Z: 115,
|
|
||||||
z: 116,
|
|
||||||
|
|
||||||
// Specials after letters (now 117-126)
|
|
||||||
'[': 117,
|
|
||||||
'\\': 118,
|
|
||||||
']': 119,
|
|
||||||
'^': 120,
|
|
||||||
_: 121,
|
|
||||||
'`': 122,
|
|
||||||
'{': 123,
|
|
||||||
'|': 124,
|
|
||||||
'}': 125,
|
|
||||||
'~': 126
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
public static GetCharWeight(char: string): number {
|
|
||||||
return this.CharTable[char as keyof typeof this.CharTable];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Regular → Executable
+58
-11
@@ -1,14 +1,10 @@
|
|||||||
import { WebG } from '$lib/shimagic/renderer/web_g_engine';
|
import { Bash, ExitCode, type Group, type User } from './bash';
|
||||||
import type { KeyBind } from '../terminal/keybindRegistry';
|
import { ls } from './commands/ls';
|
||||||
import type { Bash, Result } from './bash';
|
|
||||||
import { cd } from './commands/cd';
|
import { cd } from './commands/cd';
|
||||||
import { clear } from './commands/clear';
|
import { clear } from './commands/clear';
|
||||||
import { ls } from './commands/ls';
|
|
||||||
import { testProcess } from './commands/testAsync';
|
|
||||||
|
|
||||||
export type ICommand = {
|
export type ICommand = {
|
||||||
method: (this: Bash, args: CommandArgs) => Result;
|
method: (this: Bash, args: CommandArgs) => Result;
|
||||||
keybinds?: Map<KeyBind, () => any>;
|
|
||||||
flags: string[];
|
flags: string[];
|
||||||
help: string;
|
help: string;
|
||||||
root: boolean;
|
root: boolean;
|
||||||
@@ -19,21 +15,72 @@ export type CommandArgs = {
|
|||||||
args: string[];
|
args: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CommandResultData = {
|
export type resultData = {
|
||||||
cmd: string; //the string that contains the shorthand for the command that was executed - used in a switch statement in parseResult
|
cmd: string; //the string that contains the shorthand for the command that was executed - used in a switch statement in parseResult
|
||||||
data: any; //the data that the commmand may have returned like TreeNodes[] from ls
|
data: any; //the data that the commmand may have returned like TreeNodes[] from ls
|
||||||
args?: CommandArgs;
|
args?: CommandArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Result = {
|
||||||
|
exitCode: ExitCode;
|
||||||
|
path: number; //the inode of the place that the command was executed in
|
||||||
|
data?: resultData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GROUP: Group[] = [
|
||||||
|
{
|
||||||
|
groupname: 'sudo',
|
||||||
|
gid: 69,
|
||||||
|
members: [0, 1001]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupname: 'users',
|
||||||
|
gid: 984,
|
||||||
|
members: [1001, 1002]
|
||||||
|
}
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const PASSWD: User[] = [
|
||||||
|
{
|
||||||
|
username: 'root',
|
||||||
|
passwd: '123',
|
||||||
|
uid: 0,
|
||||||
|
gid: 0,
|
||||||
|
home: '/',
|
||||||
|
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: 'admin',
|
||||||
|
passwd: '456',
|
||||||
|
uid: 1000,
|
||||||
|
gid: 1000,
|
||||||
|
home: '/home/admin',
|
||||||
|
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: 'user',
|
||||||
|
passwd: '789',
|
||||||
|
uid: 1001,
|
||||||
|
gid: 1000,
|
||||||
|
home: '/home/user',
|
||||||
|
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: 'kamil',
|
||||||
|
passwd: '000',
|
||||||
|
uid: 1002,
|
||||||
|
gid: 1000,
|
||||||
|
home: '/home/kamil',
|
||||||
|
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
export const COMMANDS = {
|
export const COMMANDS = {
|
||||||
cd,
|
cd,
|
||||||
ls,
|
ls,
|
||||||
clear,
|
clear
|
||||||
testProcess
|
|
||||||
} as const satisfies Record<string, ICommand>;
|
} as const satisfies Record<string, ICommand>;
|
||||||
|
|
||||||
|
|
||||||
WebG.
|
|
||||||
/* //export const commands {
|
/* //export const commands {
|
||||||
return: {
|
return: {
|
||||||
method: this.cmd_return,
|
method: this.cmd_return,
|
||||||
+7
-10
@@ -4,13 +4,10 @@ import deFlag from '$lib/assets/deFlag.svg';
|
|||||||
import frFlag from '$lib/assets/frFlag.svg';
|
import frFlag from '$lib/assets/frFlag.svg';
|
||||||
import jaFlag from '$lib/assets/jaFlag.svg';
|
import jaFlag from '$lib/assets/jaFlag.svg';
|
||||||
|
|
||||||
import { writable } from 'svelte/store';
|
export const langs = {
|
||||||
|
pl: {},
|
||||||
function getInitalLocale(): string {
|
en: {},
|
||||||
if (typeof navigator === 'undefined') return 'en-US';
|
de: {},
|
||||||
|
ja: {},
|
||||||
const sysPrefLocale = navigator.language
|
fr: {}
|
||||||
return sysPrefLocale
|
};
|
||||||
}
|
|
||||||
|
|
||||||
export const locale = writable(getInitalLocale());
|
|
||||||
|
|||||||
@@ -1,281 +0,0 @@
|
|||||||
//import Renderer from '$lib/shimeji/renderer/renderer';
|
|
||||||
import { WebG } from '$lib/shimagic/renderer/web_g_engine';
|
|
||||||
import Vector2 from '../vector';
|
|
||||||
|
|
||||||
export class Shimejii {
|
|
||||||
private canvas: HTMLCanvasElement;
|
|
||||||
private renderer: Renderer;
|
|
||||||
private size: number;
|
|
||||||
|
|
||||||
private pos: Vector2 = Vector2.zero;
|
|
||||||
private vel: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private mousePos: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private pivot: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private isBeingDragged: boolean = false;
|
|
||||||
|
|
||||||
private rafId: number | null = null;
|
|
||||||
private prevDeltaTime: number = 0;
|
|
||||||
|
|
||||||
private readonly TIMESCALE: number = 1;
|
|
||||||
private readonly RESTITUTION: number = 0.4;
|
|
||||||
private readonly CURSOR_STRENGTH: number = 500;
|
|
||||||
private readonly DAMPING: number = 1;
|
|
||||||
private readonly MASS: number = 1;
|
|
||||||
private readonly FRICTION: number = 0.9;
|
|
||||||
private readonly GRAVITY: number = 50;
|
|
||||||
|
|
||||||
private bounds: { minX: number; minY: number; maxX: number; maxY: number };
|
|
||||||
|
|
||||||
constructor(size: number = 40, canvas: HTMLCanvasElement, renderer: Renderer) {
|
|
||||||
this.size = size;
|
|
||||||
this.canvas = canvas;
|
|
||||||
this.renderer = renderer;
|
|
||||||
|
|
||||||
this.bounds = {
|
|
||||||
minX: 0,
|
|
||||||
minY: 0,
|
|
||||||
maxX: window.innerWidth,
|
|
||||||
maxY: window.innerHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
this.pos.set(window.innerWidth / 2, window.innerHeight / 2);
|
|
||||||
this.vel.set(Math.floor(Math.random() * 5000) - 2500, Math.floor(Math.random() * 5000) - 2500);
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
window.addEventListener('resize', () => this.updateBounds());
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateBounds(): void {
|
|
||||||
this.bounds = {
|
|
||||||
minX: 0,
|
|
||||||
minY: 0,
|
|
||||||
maxX: window.innerWidth,
|
|
||||||
maxY: window.innerHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
this.canvas.width = window.innerWidth;
|
|
||||||
this.canvas.height = window.innerHeight;
|
|
||||||
this.renderer.UpdateBounds(window.innerWidth, window.innerHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
start(): void {
|
|
||||||
if (this.rafId !== null) return;
|
|
||||||
|
|
||||||
const firstFrame = (delta: number) => {
|
|
||||||
this.prevDeltaTime = delta;
|
|
||||||
this.rafId = requestAnimationFrame(animate);
|
|
||||||
};
|
|
||||||
|
|
||||||
const animate = (delta: number) => {
|
|
||||||
let dt = (delta - this.prevDeltaTime) / 1000;
|
|
||||||
dt = Math.min(dt, 0.05 * this.TIMESCALE);
|
|
||||||
this.prevDeltaTime = delta;
|
|
||||||
|
|
||||||
this.updatePhysics(dt);
|
|
||||||
this.applyBoundaries();
|
|
||||||
this.render();
|
|
||||||
this.rafId = requestAnimationFrame(animate);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.rafId = requestAnimationFrame(firstFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop(): void {
|
|
||||||
if (this.rafId !== null) {
|
|
||||||
cancelAnimationFrame(this.rafId);
|
|
||||||
this.rafId = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private setupDragEvents(): void {
|
|
||||||
this.element.addEventListener('mousedown', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
this.isBeingDragged = true;
|
|
||||||
this.element.style.cursor = 'grabbing';
|
|
||||||
|
|
||||||
const parent = this.element.parentElement;
|
|
||||||
if (parent) parent.style.cursor = 'grabbing';
|
|
||||||
|
|
||||||
this.pivot.x = e.offsetX - this.rect.width / 2;
|
|
||||||
this.pivot.y = e.offsetY - this.rect.height / 2;
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', (e) => {
|
|
||||||
this.mousePos.x = e.pageX;
|
|
||||||
this.mousePos.y = e.pageY;
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('mouseup', (e) => {
|
|
||||||
if (this.isBeingDragged) {
|
|
||||||
this.isBeingDragged = false;
|
|
||||||
this.element.style.cursor = 'grab';
|
|
||||||
|
|
||||||
const parent = this.element.parentElement;
|
|
||||||
if (parent) parent.style.cursor = 'auto';
|
|
||||||
|
|
||||||
this.pivot = Vector2.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.canvas.getContext('2d')!.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.element.addEventListener('dragstart', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
} */
|
|
||||||
|
|
||||||
private updatePhysics(dt: number): void {
|
|
||||||
console.log(this.vel.x, this.vel.y);
|
|
||||||
if (this.isBeingDragged) {
|
|
||||||
const direction: Vector2 = this.mousePos.sub(this.pivot).sub(this.pos);
|
|
||||||
|
|
||||||
const force: Vector2 = direction.mul(this.CURSOR_STRENGTH);
|
|
||||||
|
|
||||||
const acceleration: Vector2 = force.div(this.MASS).deadZone(0.001);
|
|
||||||
|
|
||||||
acceleration.mulEq(dt);
|
|
||||||
|
|
||||||
this.vel.addEq(acceleration);
|
|
||||||
this.vel.mulEq(0.8);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.vel.y += this.GRAVITY;
|
|
||||||
this.vel.mulEq(this.DAMPING);
|
|
||||||
|
|
||||||
if (this.pos.y + this.size >= this.bounds.maxY) {
|
|
||||||
this.vel.x *= this.FRICTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.vel.deadZoneEq(0.00001);
|
|
||||||
//if (Math.abs(this.vel.x) <= 0.00001) this.vel.x = 0;
|
|
||||||
//if (Math.abs(this.vel.y) <= 0.00001) this.vel.y = 0;
|
|
||||||
|
|
||||||
const outVel = this.vel.mul(dt);
|
|
||||||
this.pos.addEq(outVel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private applyBoundaries(): void {
|
|
||||||
const leftBound = this.size;
|
|
||||||
const rightBound = this.bounds.maxX - this.size;
|
|
||||||
|
|
||||||
if (this.pos.x < leftBound) {
|
|
||||||
this.pos.x = leftBound;
|
|
||||||
this.vel.x = -this.RESTITUTION * this.vel.x;
|
|
||||||
} else if (this.pos.x > rightBound) {
|
|
||||||
this.pos.x = rightBound;
|
|
||||||
this.vel.x = -this.RESTITUTION * this.vel.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
const topBound = this.size;
|
|
||||||
const bottomBound = this.bounds.maxY - this.size;
|
|
||||||
|
|
||||||
if (this.pos.y < topBound) {
|
|
||||||
this.pos.y = topBound;
|
|
||||||
this.vel.y = -this.RESTITUTION * this.vel.y;
|
|
||||||
} else if (this.pos.y > bottomBound) {
|
|
||||||
this.pos.y = bottomBound;
|
|
||||||
this.vel.y = -this.RESTITUTION * this.vel.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private drawRay(pos1: { x: number; y: number }, pos2: { x: number; y: number }) {
|
|
||||||
const ctx = this.canvas.getContext('2d')!;
|
|
||||||
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
ctx.strokeStyle = 'white';
|
|
||||||
ctx.lineWidth = 0.1;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(pos1.x, pos1.y);
|
|
||||||
ctx.lineTo(pos2.x, pos2.y);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private render(): void {
|
|
||||||
this.renderer.Draw(this.pos, this.size);
|
|
||||||
|
|
||||||
/* if(this.isBeingDragged) {
|
|
||||||
this.drawRay(
|
|
||||||
{x: this.mouseX, y: this.mouseY},
|
|
||||||
{x: this.x + this.pivotX, y: this.y + this.pivotY}
|
|
||||||
)
|
|
||||||
} */
|
|
||||||
}
|
|
||||||
|
|
||||||
addImpulse(x: number, y: number): void {
|
|
||||||
this.vel.x += x;
|
|
||||||
this.vel.y += y;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveTo(pos: number) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace Shimagic {
|
|
||||||
export class Shimeji {
|
|
||||||
private WebGEngine: WebG.Engine;
|
|
||||||
//private PhysisEngine: Physis.Engine;
|
|
||||||
private size!: number;
|
|
||||||
|
|
||||||
private AnimID: number | null = null;
|
|
||||||
private pDeltaT: number = 0;
|
|
||||||
|
|
||||||
constructor(webgengine: WebG.Engine /* physis: Physis.Engine */) {
|
|
||||||
this.WebGEngine = webgengine;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method: Initializes all sub-systems like WebG & Physis aswell as initializes the Shimeji and starts its animation
|
|
||||||
* @async
|
|
||||||
* @public
|
|
||||||
* @param {ShimejiConfig} config - Shimeji configuration
|
|
||||||
* @returns {Promise<Shimeji>} that resolves when the Shimeji is done initializing
|
|
||||||
*/
|
|
||||||
public static async Initialize(config: ShimejiConfig): Promise<Shimeji> {
|
|
||||||
const webg = await WebG.Engine.Initialize(config.webG);
|
|
||||||
//const physis = await Physis.Engine.Initialize(config.physis);
|
|
||||||
|
|
||||||
const shimeji = new Shimeji(webg);
|
|
||||||
shimeji.size = config.size;
|
|
||||||
|
|
||||||
const AFrame = (delta: number) => {
|
|
||||||
shimeji.pDeltaT = delta;
|
|
||||||
shimeji.AnimID = requestAnimationFrame(shimeji._anim);
|
|
||||||
};
|
|
||||||
|
|
||||||
shimeji.AnimID = requestAnimationFrame(AFrame);
|
|
||||||
|
|
||||||
return shimeji;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _anim(delta: number) {
|
|
||||||
let dt = (delta - this.pDeltaT) / 1000;
|
|
||||||
dt = Math.min(dt, 0.05 /* * this.Physis.TIMESCALE */);
|
|
||||||
this.pDeltaT = delta;
|
|
||||||
|
|
||||||
this.UpdatePhysics(dt);
|
|
||||||
this.UpdateFrame(dt);
|
|
||||||
|
|
||||||
this.AnimID = requestAnimationFrame(this._anim);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A function called automatically every "frame" where the code for calculating the next physics frame of the Shimeji is placed
|
|
||||||
* @param delta - Automatically passed in deltaT value;
|
|
||||||
*/
|
|
||||||
private UpdatePhysics(delta: number): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A function called automatically every "frame" where the code for drawing the next frame of the Shimeji is placed
|
|
||||||
* @param delta - Automatically passed in deltaT value;
|
|
||||||
*/
|
|
||||||
private UpdateFrame(delta: number): void {}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ShimejiConfig {
|
|
||||||
sprite: string; //temp soultion to
|
|
||||||
size: number;
|
|
||||||
webG: WebG.EngineConfig;
|
|
||||||
//physis: Physis.EngineConfig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,336 +0,0 @@
|
|||||||
import Vector2 from "../vector";
|
|
||||||
|
|
||||||
export class Shimeji {
|
|
||||||
private element: HTMLElement;
|
|
||||||
private canvas: HTMLCanvasElement;
|
|
||||||
private rect: DOMRect;
|
|
||||||
|
|
||||||
private pos: Vector2 = Vector2.zero;
|
|
||||||
private vel: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private angle: number = 0; // radians
|
|
||||||
private angularVelocity: number = 0; // rad/s
|
|
||||||
private inertia: number; // kg·m²
|
|
||||||
private localGrip: Vector2 = Vector2.zero; // offset from center (body‑fixed)
|
|
||||||
|
|
||||||
private mousePos: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private pivot: Vector2 = Vector2.zero;
|
|
||||||
|
|
||||||
private isBeingDragged: boolean = false;
|
|
||||||
|
|
||||||
private rafId: number | null = null;
|
|
||||||
private prevDeltaTime: number = 0;
|
|
||||||
|
|
||||||
|
|
||||||
private readonly RESTITUTION: number = 0.6;
|
|
||||||
private readonly STIFFNESS: number = 500;
|
|
||||||
private readonly DAMPING: number = 1;
|
|
||||||
private readonly MASS: number = 10.0;
|
|
||||||
private readonly FRICTION: number = 0.9;
|
|
||||||
private readonly GRAVITY: number = 10;
|
|
||||||
|
|
||||||
private bounds: { minX: number; minY: number; maxX: number; maxY: number };
|
|
||||||
|
|
||||||
constructor(element: HTMLElement, canvas: HTMLCanvasElement) {
|
|
||||||
this.element = element;
|
|
||||||
this.canvas= canvas;
|
|
||||||
this.rect = element.getBoundingClientRect();
|
|
||||||
|
|
||||||
this.bounds = {
|
|
||||||
minX: 0,
|
|
||||||
minY: 0,
|
|
||||||
maxX: window.innerWidth,
|
|
||||||
maxY: window.innerHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
this.inertia = (1 / 12) *
|
|
||||||
this.MASS * (this.rect.width * this.rect.width + this.rect.height * this.rect.height);
|
|
||||||
|
|
||||||
this.pos.set(window.innerWidth / 2, window.innerHeight/ 2);
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
window.addEventListener('resize', () => this.updateBounds());
|
|
||||||
|
|
||||||
console.log(this.element.getBoundingClientRect());
|
|
||||||
|
|
||||||
this.setupDragEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateBounds(): void {
|
|
||||||
this.bounds = {
|
|
||||||
minX: 0,
|
|
||||||
minY: 0,
|
|
||||||
maxX: window.innerWidth,
|
|
||||||
maxY: window.innerHeight
|
|
||||||
};
|
|
||||||
|
|
||||||
this.canvas.width = window.innerWidth;
|
|
||||||
this.canvas.height = window.innerHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
start(): void {
|
|
||||||
if (this.rafId !== null) return;
|
|
||||||
|
|
||||||
const firstFrame = (delta: number) => {
|
|
||||||
this.prevDeltaTime = delta;
|
|
||||||
this.rafId = requestAnimationFrame(animate);
|
|
||||||
}
|
|
||||||
|
|
||||||
const animate = (delta: number) => {
|
|
||||||
const dt: number = Math.min(delta - this.prevDeltaTime, 0.05);
|
|
||||||
this.prevDeltaTime = delta;
|
|
||||||
|
|
||||||
this.updatePhysics(dt);
|
|
||||||
this.applyBoundaries();
|
|
||||||
this.render();
|
|
||||||
this.rafId = requestAnimationFrame(animate);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.rafId = requestAnimationFrame(firstFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop(): void {
|
|
||||||
if (this.rafId !== null) {
|
|
||||||
cancelAnimationFrame(this.rafId);
|
|
||||||
this.rafId = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCornerWorld(lx: number, ly: number): Vector2 {
|
|
||||||
// lx, ly are in local coordinates (relative to center, with rotation)
|
|
||||||
const cos = Math.cos(this.angle);
|
|
||||||
const sin = Math.sin(this.angle);
|
|
||||||
return new Vector2(
|
|
||||||
this.pos.x + (lx * cos - ly * sin),
|
|
||||||
this.pos.y + (lx * sin + ly * cos)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setupDragEvents(): void {
|
|
||||||
this.element.addEventListener('mousedown', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
this.isBeingDragged = true;
|
|
||||||
this.element.style.cursor = 'grabbing';
|
|
||||||
|
|
||||||
const parent = this.element.parentElement;
|
|
||||||
if(parent) parent.style.cursor = 'grabbing';
|
|
||||||
|
|
||||||
const clickWorld = new Vector2(e.pageX, e.pageY);
|
|
||||||
const center = this.pos;
|
|
||||||
const offset = clickWorld.sub(center)
|
|
||||||
const cos = Math.cos(-this.angle);
|
|
||||||
const sin = Math.sin(-this.angle);
|
|
||||||
|
|
||||||
this.localGrip = new Vector2(
|
|
||||||
offset.x * cos - offset.y * sin,
|
|
||||||
offset.x * sin + offset.y * cos
|
|
||||||
);
|
|
||||||
|
|
||||||
this.pivot.x = e.offsetX - this.rect.width / 2;
|
|
||||||
this.pivot.y = e.offsetY - this.rect.height / 2;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', (e) => {
|
|
||||||
this.mousePos.x = e.pageX;
|
|
||||||
this.mousePos.y = e.pageY;
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('mouseup', (e) => {
|
|
||||||
if(this.isBeingDragged) {
|
|
||||||
this.isBeingDragged = false;
|
|
||||||
this.element.style.cursor = 'grab';
|
|
||||||
|
|
||||||
const parent = this.element.parentElement;
|
|
||||||
if(parent) parent.style.cursor = 'auto';
|
|
||||||
|
|
||||||
this.pivot = Vector2.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.canvas.getContext('2d')!.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.element.addEventListener('dragstart', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private updatePhysics(dt: number): void {
|
|
||||||
|
|
||||||
const cos = Math.cos(this.angle);
|
|
||||||
const sin = Math.sin(this.angle);
|
|
||||||
const gripWorld = new Vector2(
|
|
||||||
this.pos.x + (this.localGrip.x * cos - this.localGrip.y * sin),
|
|
||||||
this.pos.y + (this.localGrip.x * sin + this.localGrip.y * cos)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.isBeingDragged) {
|
|
||||||
const direction: Vector2 = this.mousePos.sub(gripWorld);
|
|
||||||
|
|
||||||
const force: Vector2 = direction.mul(this.STIFFNESS);
|
|
||||||
|
|
||||||
const acceleration: Vector2 = force.div(this.MASS).deadZone(0.001);
|
|
||||||
|
|
||||||
acceleration.mulEq(dt);
|
|
||||||
|
|
||||||
this.vel.addEq(acceleration);
|
|
||||||
this.vel.mulEq(0.8);
|
|
||||||
|
|
||||||
const r = gripWorld.sub(this.pos);
|
|
||||||
const torque = r.cross(force);
|
|
||||||
this.angularVelocity += (torque / this.inertia) * dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.vel.y += this.GRAVITY;
|
|
||||||
this.vel.mulEq(this.DAMPING);
|
|
||||||
|
|
||||||
if (this.pos.y + this.rect.width >= this.bounds.maxY) {
|
|
||||||
this.vel.x *= this.FRICTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
const outVel = this.vel.mul(dt);
|
|
||||||
this.pos.addEq(outVel);
|
|
||||||
|
|
||||||
this.angle += this.angularVelocity * dt;
|
|
||||||
this.angle %= 2 * Math.PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
private applyBoundaries(): void {
|
|
||||||
const w = this.rect.width / 2;
|
|
||||||
const h = this.rect.height / 2;
|
|
||||||
|
|
||||||
// List of corners in local coordinates (four combinations)
|
|
||||||
const corners = [
|
|
||||||
{ lx: w, ly: h }, // top‑right
|
|
||||||
{ lx: w, ly: -h }, // bottom‑right
|
|
||||||
{ lx: -w, ly: h }, // top‑left
|
|
||||||
{ lx: -w, ly: -h } // bottom‑left
|
|
||||||
];
|
|
||||||
|
|
||||||
// Check each wall
|
|
||||||
// Left wall (x = leftBound)
|
|
||||||
const leftBound = w;
|
|
||||||
for (const corner of corners) {
|
|
||||||
const world = this.getCornerWorld(corner.lx, corner.ly);
|
|
||||||
if (world.x < leftBound) {
|
|
||||||
// Penetration depth (distance from wall to corner)
|
|
||||||
const penetration = leftBound - world.x;
|
|
||||||
// Normal points to the right (+x)
|
|
||||||
const normal = new Vector2(1, 0);
|
|
||||||
// Contact point is the wall at corner's y (or clamp to avoid escaping)
|
|
||||||
const contactY = Math.min(Math.max(world.y, this.bounds.minY + h), this.bounds.maxY - h);
|
|
||||||
const contactPoint = new Vector2(leftBound, contactY);
|
|
||||||
this.resolveCollision(normal, contactPoint);
|
|
||||||
// Reposition to avoid continuous penetration
|
|
||||||
this.pos.x = leftBound - w;
|
|
||||||
return; // after one correction, stop checking further walls to avoid multiple impulses
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right wall (x = rightBound)
|
|
||||||
const rightBound = this.bounds.maxX - w;
|
|
||||||
for (const corner of corners) {
|
|
||||||
const world = this.getCornerWorld(corner.lx, corner.ly);
|
|
||||||
if (world.x > rightBound) {
|
|
||||||
const penetration = world.x - rightBound;
|
|
||||||
const normal = new Vector2(-1, 0);
|
|
||||||
const contactY = Math.min(Math.max(world.y, this.bounds.minY + h), this.bounds.maxY - h);
|
|
||||||
const contactPoint = new Vector2(rightBound, contactY);
|
|
||||||
this.resolveCollision(normal, contactPoint);
|
|
||||||
this.pos.x = rightBound + w;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top wall (y = topBound)
|
|
||||||
const topBound = h;
|
|
||||||
for (const corner of corners) {
|
|
||||||
const world = this.getCornerWorld(corner.lx, corner.ly);
|
|
||||||
if (world.y < topBound) {
|
|
||||||
const penetration = topBound - world.y;
|
|
||||||
const normal = new Vector2(0, 1);
|
|
||||||
const contactX = Math.min(Math.max(world.x, leftBound), rightBound);
|
|
||||||
const contactPoint = new Vector2(contactX, topBound);
|
|
||||||
this.resolveCollision(normal, contactPoint);
|
|
||||||
this.pos.y = topBound - h;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom wall (y = bottomBound)
|
|
||||||
const bottomBound = this.bounds.maxY - h;
|
|
||||||
for (const corner of corners) {
|
|
||||||
const world = this.getCornerWorld(corner.lx, corner.ly);
|
|
||||||
if (world.y > bottomBound) {
|
|
||||||
const penetration = world.y - bottomBound;
|
|
||||||
const normal = new Vector2(0, -1);
|
|
||||||
const contactX = Math.min(Math.max(world.x, leftBound), rightBound);
|
|
||||||
const contactPoint = new Vector2(contactX, bottomBound);
|
|
||||||
this.resolveCollision(normal, contactPoint);
|
|
||||||
this.pos.y = bottomBound + h;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private resolveCollision(normal: Vector2, contactPoint: Vector2): void {
|
|
||||||
// Vector from center to contact point
|
|
||||||
const r = contactPoint.sub(this.pos);
|
|
||||||
|
|
||||||
// Velocity of the contact point
|
|
||||||
const v_rel = this.vel.clone();
|
|
||||||
// Add tangential component from angular velocity: ω × r
|
|
||||||
v_rel.x -= this.angularVelocity * r.y;
|
|
||||||
v_rel.y += this.angularVelocity * r.x;
|
|
||||||
|
|
||||||
// Relative velocity along normal
|
|
||||||
const vn = v_rel.dot(normal);
|
|
||||||
if (vn > 0) return; // Already separating
|
|
||||||
|
|
||||||
// Impulse numerator
|
|
||||||
const numerator = -(1 + this.RESTITUTION) * vn;
|
|
||||||
|
|
||||||
// Denominator: 1/m + (r × n)^2 / I
|
|
||||||
const r_cross_n = r.cross(normal);
|
|
||||||
const denominator = 1 / this.MASS + (r_cross_n * r_cross_n) / this.inertia;
|
|
||||||
|
|
||||||
const j = numerator / denominator;
|
|
||||||
const impulse = normal.mul(j);
|
|
||||||
|
|
||||||
// Apply impulse
|
|
||||||
this.vel.addEq(impulse.div(this.MASS));
|
|
||||||
this.angularVelocity += r.cross(impulse) / this.inertia;
|
|
||||||
}
|
|
||||||
|
|
||||||
private drawRay(pos1: {x: number, y: number}, pos2: {x: number, y: number}) {
|
|
||||||
const ctx = this.canvas.getContext("2d")!;
|
|
||||||
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
ctx.strokeStyle = "white";
|
|
||||||
ctx.lineWidth = 0.1
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(pos1.x, pos1.y);
|
|
||||||
ctx.lineTo(pos2.x, pos2.y);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private render(): void {
|
|
||||||
this.element.style.transform = `translate(${this.pos.x}px, ${this.pos.y}px) rotate(${this.angle * 180 / Math.PI}deg)`;
|
|
||||||
|
|
||||||
/* if(this.isBeingDragged) {
|
|
||||||
this.drawRay(
|
|
||||||
{x: this.mousePos.x, y: this.mousePos.y},
|
|
||||||
{x: this.pos.x + this.pivot.x, y: this.pos.y + this.pivot.y}
|
|
||||||
)
|
|
||||||
} */
|
|
||||||
}
|
|
||||||
|
|
||||||
addImpulse(x: number, y: number): void {
|
|
||||||
this.vel.x += x;
|
|
||||||
this.vel.y += y;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveTo(pos: number) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import type { User } from '../bash/bash';
|
||||||
import type { TreeNode } from '../bash/fs';
|
import type { TreeNode } from '../bash/fs';
|
||||||
//import { type ILocale } from './localeRegistry';
|
import { Terminal, type TermInitArgs } from './terminal';
|
||||||
import { Terminal, type PageCallbacks, type TermInitArgs } from './terminal';
|
|
||||||
|
|
||||||
let initializing = $state(true);
|
let initializing = $state(true);
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ export function isInitializing(): boolean {
|
|||||||
return initializing;
|
return initializing;
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
function jsonToNodeTable(data: any): Map<number, TreeNode> {
|
||||||
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
||||||
const entryList = Object.entries(data);
|
const entryList = Object.entries(data);
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ function jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
|||||||
func: object.Func,
|
func: object.Func,
|
||||||
children: object.Children,
|
children: object.Children,
|
||||||
content: object.Content,
|
content: object.Content,
|
||||||
link: object.Target,
|
link: object.Link,
|
||||||
permission: {
|
permission: {
|
||||||
user: {
|
user: {
|
||||||
r: object.Permission[0]?.Read,
|
r: object.Permission[0]?.Read,
|
||||||
@@ -56,7 +56,7 @@ function jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
|||||||
return FsTable;
|
return FsTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchFsJson(sig: string): Promise<JSON> {
|
async function fetchFsJson(sig: string): Promise<any> {
|
||||||
const signature: string | null = localStorage.getItem('signature');
|
const signature: string | null = localStorage.getItem('signature');
|
||||||
|
|
||||||
if (signature !== sig || signature === null || localStorage.getItem('fs') === null) {
|
if (signature !== sig || signature === null || localStorage.getItem('fs') === null) {
|
||||||
@@ -99,33 +99,16 @@ async function fetchFileSystem(path: string): Promise<any> {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchLocale(id: string): Promise<any> {
|
export async function initTerminal(user: User, callbackInit: any): Promise<Terminal> {
|
||||||
const response = await fetch(`/src/lib/assets/locales/terminal/${id}.json`);
|
|
||||||
if (!response.ok) throw new Error('Failed to fetch the chosen locale');
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function initTerminal(
|
|
||||||
user: { username: string; password: string },
|
|
||||||
callbackInit: PageCallbacks,
|
|
||||||
localeId: string
|
|
||||||
): Promise<Shell> {
|
|
||||||
try {
|
try {
|
||||||
const sig = await fetchFsSignature('/src/lib/assets/fs/signature');
|
const sig = await fetchFsSignature('/src/lib/assets/fs/signature');
|
||||||
const fsJson: JSON = await fetchFsJson(sig);
|
const fsJson = await fetchFsJson(sig);
|
||||||
const fs: Map<number, TreeNode> = jsonToNodeTable(fsJson);
|
const fs: Map<number, TreeNode> = jsonToNodeTable(fsJson);
|
||||||
/* const locale: ILocale = {
|
|
||||||
id: localeId,
|
|
||||||
keys: fetchLocale(localeId)
|
|
||||||
}; */
|
|
||||||
|
|
||||||
const args: TermInitArgs = {
|
const args: TermInitArgs = {
|
||||||
//locale,
|
|
||||||
bash: {
|
bash: {
|
||||||
fs,
|
user,
|
||||||
user
|
fs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
export type Modifier = 'Ctrl' | 'Alt' | 'Shift';
|
|
||||||
|
|
||||||
type KeyStroke = {
|
|
||||||
key: string;
|
|
||||||
modifiers?: Modifier[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type KeyBind = [KeyStroke] | [KeyStroke, KeyStroke];
|
|
||||||
|
|
||||||
const sigint: KeyBind = [{
|
|
||||||
key: 'c',
|
|
||||||
modifiers: ['Ctrl']
|
|
||||||
}];
|
|
||||||
|
|
||||||
export const TERMINAL_KEYBINDS = {
|
|
||||||
sigint
|
|
||||||
} as const satisfies Record<string, KeyBind>;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* export interface ILocale {
|
|
||||||
id: string;
|
|
||||||
keys?: {};
|
|
||||||
SetKeys: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const en_US: ILocale = {
|
|
||||||
id: 'en_US',
|
|
||||||
keys: {},
|
|
||||||
|
|
||||||
SetKeys(): () {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LOCALES = {
|
|
||||||
en_US
|
|
||||||
} as const satisfies Record<string, ILocale>; */
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { mount, unmount } from 'svelte';
|
import { mount, unmount } from 'svelte';
|
||||||
import Output from '../../../../modules/terminal/Output.svelte';
|
import Output from '../../../modules/terminal/Output.svelte';
|
||||||
import { isInitializing } from '../init.svelte';
|
import { isInitializing } from './init.svelte';
|
||||||
import type { PrintData } from '../terminal';
|
import type { PrintData } from './terminal';
|
||||||
|
|
||||||
interface OutputProps {
|
interface OutputProps {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -23,8 +23,6 @@ function appendOutput(container: HTMLElement, props: OutputProps): Output | unde
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function print(e: HTMLElement, data: PrintData): void {
|
export function print(e: HTMLElement, data: PrintData): void {
|
||||||
if (data.cmd == 'clear') return;
|
|
||||||
|
|
||||||
if (isInitializing()) {
|
if (isInitializing()) {
|
||||||
console.error('Terminal is initializing! Skipping Print');
|
console.error('Terminal is initializing! Skipping Print');
|
||||||
return;
|
return;
|
||||||
@@ -37,7 +35,6 @@ export function print(e: HTMLElement, data: PrintData): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function clear(): void {
|
export function clear(): void {
|
||||||
for (const instance of outputInstances) {
|
console.log("outInstances", outputInstances);
|
||||||
unmount(instance, {});
|
unmount(outputInstances);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,12 @@
|
|||||||
import { Bash, type BashInitArgs, type Result } from '../bash/bash';
|
import { Bash, ExitCode, type BashInitArgs, type User } from '../bash/bash';
|
||||||
import type { CommandArgs } from '../bash/commandRegistry';
|
import type { VirtualFS } from '../bash/fs';
|
||||||
import type { User } from '../bash/etc/userData';
|
import type { CommandArgs } from '../bash/static';
|
||||||
import { VirtualFS } from '../bash/fs';
|
import { Char } from '../char';
|
||||||
import { KeybindInhibitor } from '../bash/keybindInhibitor';
|
|
||||||
import { ExitCode } from '../bash/metadata';
|
|
||||||
import type { Process } from '../bash/process';
|
|
||||||
import { TERMINAL_KEYBINDS, type KeyBind } from './keybindRegistry';
|
|
||||||
//import type { ILocale } from './localeRegistry';
|
|
||||||
|
|
||||||
export type TerminalMode = {};
|
export type TerminalMode = {};
|
||||||
|
|
||||||
export type TermInitArgs = {
|
export type TermInitArgs = {
|
||||||
bash: BashInitArgs;
|
bash: BashInitArgs;
|
||||||
//locale: ILocale
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ParsedInput = {
|
export type ParsedInput = {
|
||||||
@@ -33,41 +27,13 @@ export type PageCallbacks = {
|
|||||||
getFontSize: () => number;
|
getFontSize: () => number;
|
||||||
};
|
};
|
||||||
|
|
||||||
TermOS.Shell;
|
|
||||||
|
|
||||||
export class Terminal {
|
export class Terminal {
|
||||||
private _bash: Bash;
|
private bash: Bash;
|
||||||
private _callbacks: Partial<PageCallbacks> = {};
|
private callbacks: Partial<PageCallbacks> = {};
|
||||||
private _keybindInhibitor: KeybindInhibitor;
|
|
||||||
|
|
||||||
//public isProcessActive: boolean = false;
|
|
||||||
//public locale: ILocale;
|
|
||||||
|
|
||||||
constructor(args: TermInitArgs) {
|
constructor(args: TermInitArgs) {
|
||||||
args.bash.io = this;
|
args.bash.stdio = this;
|
||||||
this._bash = new Bash(args.bash);
|
this.bash = new Bash(args.bash);
|
||||||
|
|
||||||
const keybinds: Map<KeyBind, () => any> = new Map([
|
|
||||||
[TERMINAL_KEYBINDS.sigint, this._processKill]
|
|
||||||
]);
|
|
||||||
|
|
||||||
this._keybindInhibitor = new KeybindInhibitor(keybinds);
|
|
||||||
|
|
||||||
//this.locale = args.locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _processKill(): ExitCode {
|
|
||||||
const get: Process | ExitCode = this._bash.getProcess();
|
|
||||||
if (get == ExitCode.ERROR) return ExitCode.ERROR;
|
|
||||||
|
|
||||||
const process: Process = get;
|
|
||||||
const result = process.sigKill(() => {
|
|
||||||
console.log('process kill successful');
|
|
||||||
});
|
|
||||||
|
|
||||||
//this.isProcessActive = false;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _parseInput(input: string): ParsedInput {
|
private _parseInput(input: string): ParsedInput {
|
||||||
@@ -123,74 +89,47 @@ export class Terminal {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
throwExeption(message: string, exitCode: ExitCode) {
|
executeCommand(input: string): void {
|
||||||
console.error(message, exitCode);
|
this.bash.updateHistory(input);
|
||||||
}
|
|
||||||
|
|
||||||
executeCommand(input: string): Promise<Result> {
|
|
||||||
this._bash.updateHistory(input);
|
|
||||||
const parsed: ParsedInput = this._parseInput(input);
|
const parsed: ParsedInput = this._parseInput(input);
|
||||||
//console.log(parsed, 'executeCommand output');
|
console.log(parsed, 'executeCommand output');
|
||||||
|
this.bash.executeCommand(parsed.command, parsed.args);
|
||||||
return this._bash.executeCommand(parsed.command, parsed.args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCallbacks(callbacks: PageCallbacks): void {
|
registerCallbacks(callbacks: PageCallbacks): void {
|
||||||
this._callbacks = callbacks;
|
this.callbacks = callbacks;
|
||||||
}
|
|
||||||
|
|
||||||
clearTerminal() {
|
|
||||||
this._callbacks.clear?.();
|
|
||||||
}
|
|
||||||
|
|
||||||
getPrimaryKeybindInhibitor(): KeybindInhibitor {
|
|
||||||
const processKeybinds: KeybindInhibitor | null = this._bash.getProcessKeybindInhibitor();
|
|
||||||
if (processKeybinds) {
|
|
||||||
return processKeybinds;
|
|
||||||
} else {
|
|
||||||
return this._keybindInhibitor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getProcessKeyInhibitor(): KeybindInhibitor | ExitCode.ERROR {
|
|
||||||
const out = this._bash.getProcessKeybindInhibitor();
|
|
||||||
if (out) return out;
|
|
||||||
else return ExitCode.ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
getKeybindInhibitor(): KeybindInhibitor {
|
|
||||||
return this._keybindInhibitor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser(): User {
|
getUser(): User {
|
||||||
return this._bash.getUser();
|
return this.bash.getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
getTerminalWidth(): number {
|
getTerminalWidth(): number {
|
||||||
const width = this._callbacks.getWidth?.();
|
const width = this.callbacks.getWidth?.();
|
||||||
if (!width) {
|
if(!width) { throw new Error('somehow width is undefined still after all the checks'); }
|
||||||
throw new Error('somehow width is undefined still after all the checks');
|
|
||||||
}
|
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFontSize(): number {
|
getFontSize(): number {
|
||||||
const size = this._callbacks.getFontSize?.();
|
const size = this.callbacks.getFontSize?.();
|
||||||
if (!size) {
|
if(!size) { throw new Error('somehow font size is undefined still after all the checks'); }
|
||||||
throw new Error('somehow font size is undefined still after all the checks');
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCwd(): string {
|
getCwd(): string {
|
||||||
const fs: VirtualFS = this._bash.getFs();
|
const fs: VirtualFS = this.bash.getFs();
|
||||||
console.log(fs.getPathByInode(this._bash.getCwd()));
|
console.log(fs.getPathByInode(this.bash.getCwd()));
|
||||||
return fs.formatPath(fs.getPathByInode(this._bash.getCwd()));
|
return fs.formatPath(fs.getPathByInode(this.bash.getCwd()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Later reimplement the backend helper methods
|
||||||
|
/* userLogin(username: string, passwd: string): ExitCode {
|
||||||
|
return this.bash.userLogin(username, passwd);
|
||||||
|
} */
|
||||||
|
|
||||||
PrintOutput(data: PrintData) {
|
PrintOutput(data: PrintData) {
|
||||||
this._callbacks.print?.(data);
|
this.callbacks.print?.(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
import { Command } from '../shell/command';
|
|
||||||
|
|
||||||
export class cd extends Command {}
|
|
||||||
@@ -1,353 +0,0 @@
|
|||||||
import type { User } from '../shell/shell';
|
|
||||||
|
|
||||||
export class FileSystem {
|
|
||||||
static #instance: FileSystem;
|
|
||||||
private _fs: Map<number, TreeNode>;
|
|
||||||
private _root: number;
|
|
||||||
|
|
||||||
private constructor(fs: Map<number, TreeNode>) {
|
|
||||||
this._fs = fs;
|
|
||||||
this._root = this._fs.values().next().value!.inode;
|
|
||||||
|
|
||||||
if (!this._root) throw new Error('First entry in the filesystem map empty!');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Init(fsJson: JSON) {
|
|
||||||
//const fsChecksum = MD5.hash(JSON.stringify(fsJson));
|
|
||||||
|
|
||||||
/*
|
|
||||||
const cache: string | null = localStorage.getItem('fs-json');
|
|
||||||
if (cache) {
|
|
||||||
const fsCacheChecksum = MD5.hash(cache);
|
|
||||||
|
|
||||||
console.log(fsChecksum);
|
|
||||||
console.log(fsCacheChecksum);
|
|
||||||
|
|
||||||
if (fsChecksum !== fsCacheChecksum) {
|
|
||||||
//calculate version control difference to preserve user made changes (do a merge)
|
|
||||||
}
|
|
||||||
fsJson = JSON.parse(cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem('fs-json', JSON.stringify(fsJson));
|
|
||||||
*/
|
|
||||||
|
|
||||||
const fs: Map<number, TreeNode> = this._jsonToNodeTable(fsJson);
|
|
||||||
|
|
||||||
// This produces a different checksum!
|
|
||||||
// Find a way to produce the same hash from Map and a fetched json file or cached stringified json
|
|
||||||
|
|
||||||
FileSystem.#instance = new FileSystem(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private async _fetchFsSignature(path: string): Promise<any> {
|
|
||||||
try {
|
|
||||||
const response = await fetch(path);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.text();
|
|
||||||
return data.slice(0, 36); //32 characters of uuid + 4 dashes
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch the file system signature', error);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
/* private static async fetchFsJson(): Promise<JSON> {
|
|
||||||
const checksum: string | null = localStorage.getItem('fs-checksum');
|
|
||||||
|
|
||||||
if (checksum !== sig || signature === null || localStorage.getItem('fs') === null) {
|
|
||||||
const fs: JSON = await this._fetchFileSystem('/src/lib/assets/fs/fs.json');
|
|
||||||
localStorage.setItem('signature', sig);
|
|
||||||
localStorage.setItem('fs', JSON.stringify(fs));
|
|
||||||
|
|
||||||
console.info('FS fetched from file, new sinature:', sig);
|
|
||||||
|
|
||||||
return fs;
|
|
||||||
} else {
|
|
||||||
const fs: string | null = localStorage.getItem('fs');
|
|
||||||
if (fs === null) throw new Error('FS in LocalStorage is null!');
|
|
||||||
|
|
||||||
console.info('FS fetched from localStorage with signature:', sig);
|
|
||||||
|
|
||||||
return JSON.parse(fs);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
private static _jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
|
||||||
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
|
||||||
const entryList = Object.entries(data);
|
|
||||||
|
|
||||||
for (let i = 0; i < entryList.length; i++) {
|
|
||||||
const object: any = entryList[i][1];
|
|
||||||
const node: TreeNode = {
|
|
||||||
inode: object.Inode,
|
|
||||||
name: object.Name,
|
|
||||||
type: object.Type,
|
|
||||||
size: object.Size,
|
|
||||||
interactible: object.Interactible,
|
|
||||||
func: object.Func,
|
|
||||||
children: object.Children,
|
|
||||||
content: object.Content,
|
|
||||||
link: object.Target,
|
|
||||||
permission: {
|
|
||||||
user: {
|
|
||||||
r: object.Permission[0]?.Read,
|
|
||||||
w: object.Permission[0]?.Write,
|
|
||||||
x: object.Permission[0]?.Exec
|
|
||||||
},
|
|
||||||
group: {
|
|
||||||
r: object.Permission[1]?.Read,
|
|
||||||
w: object.Permission[1]?.Write,
|
|
||||||
x: object.Permission[1]?.Exec
|
|
||||||
},
|
|
||||||
other: {
|
|
||||||
r: object.Permission[2]?.Read,
|
|
||||||
w: object.Permission[2]?.Write,
|
|
||||||
x: object.Permission[2]?.Exec
|
|
||||||
}
|
|
||||||
},
|
|
||||||
owner: object.Owner,
|
|
||||||
group: object.Group,
|
|
||||||
timestamps: {
|
|
||||||
modified: new Date(object.TimeStamps.MTime),
|
|
||||||
changed: new Date(object.TimeStamps.CTime),
|
|
||||||
accessed: new Date(object.TimeStamps.ATime)
|
|
||||||
},
|
|
||||||
parent: object.Parent
|
|
||||||
};
|
|
||||||
|
|
||||||
FsTable.set(object.Inode, node);
|
|
||||||
}
|
|
||||||
return FsTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _createNode(name: string, type: Type, path: number, user: User): void {
|
|
||||||
const currTime: Date = new Date();
|
|
||||||
|
|
||||||
const node: TreeNode = {
|
|
||||||
parent: path,
|
|
||||||
inode: this._fs.size + 1,
|
|
||||||
name: name,
|
|
||||||
type: type,
|
|
||||||
size: 4096,
|
|
||||||
children: [],
|
|
||||||
content: '',
|
|
||||||
link: -1,
|
|
||||||
permission: {
|
|
||||||
user: {
|
|
||||||
r: true,
|
|
||||||
w: true,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
group: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
other: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
owner: user.uid,
|
|
||||||
group: user.gid,
|
|
||||||
timestamps: {
|
|
||||||
modified: currTime,
|
|
||||||
changed: currTime,
|
|
||||||
accessed: currTime
|
|
||||||
},
|
|
||||||
interactible: false,
|
|
||||||
func: null
|
|
||||||
};
|
|
||||||
|
|
||||||
this._fs.set(this._fs.size + 1, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _deleteNode(inode: number): void {
|
|
||||||
this._fs.delete(inode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _iNodeToPathString(inode: number): string {
|
|
||||||
const currentNode = this._fs.get(inode);
|
|
||||||
|
|
||||||
if (!currentNode)
|
|
||||||
throw new Error(`Failed to parse the path from inode, inode doesnt exist - ${inode}`);
|
|
||||||
if (!currentNode.parent || currentNode.inode === this._root) return '/';
|
|
||||||
|
|
||||||
const parentPath: string | null = this._iNodeToPathString(currentNode.parent);
|
|
||||||
if (!parentPath)
|
|
||||||
throw new Error(
|
|
||||||
`Failed to parse the path from inode, inode doesnt exist - ${currentNode.parent}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return parentPath === '/' ? `/${currentNode.name}` : `${parentPath}/${currentNode.name}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _pathStringToNode(path: string): TreeNode {
|
|
||||||
// Truncates all slatshes at the start and end of the string
|
|
||||||
const normalizedPath: string = path.replace(/^\/+|\/+$/g, '');
|
|
||||||
|
|
||||||
// Splits the path to node names and filters them out from empty strings
|
|
||||||
const pathComponents: string[] = normalizedPath.split('/').filter((node) => node.length > 0);
|
|
||||||
|
|
||||||
let currentNode: TreeNode | undefined = this._fs.get(this._root);
|
|
||||||
if (!currentNode)
|
|
||||||
throw new Error(`WARNING! - Root node not found under FileSystem._root - ${this._root}`);
|
|
||||||
if (pathComponents.length === 0) return currentNode;
|
|
||||||
|
|
||||||
for (const component of pathComponents) {
|
|
||||||
const childINode: number = this._getChildNodeByName(currentNode!, component)?.inode;
|
|
||||||
|
|
||||||
if (!childINode)
|
|
||||||
throw new Error(`Failed to parse the child node from path, is the path correct?`);
|
|
||||||
|
|
||||||
const nextNode = this._fs.get(childINode);
|
|
||||||
if (!nextNode)
|
|
||||||
throw new Error(`Failed to parse the child node from path, is the path correct?`);
|
|
||||||
|
|
||||||
currentNode = nextNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getChildNodeByName(node: TreeNode, name: string): TreeNode {
|
|
||||||
for (const inode of node.children) {
|
|
||||||
const child = this._fs.get(inode);
|
|
||||||
if (child && child.name === name) return child;
|
|
||||||
}
|
|
||||||
throw new Error(
|
|
||||||
`Node under the name ${name} not found in the child list of ${node.name} - ${node.inode}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _isAbsolutePath = (path: string): boolean => {
|
|
||||||
return typeof path === 'string' && path.startsWith('/');
|
|
||||||
};
|
|
||||||
|
|
||||||
public getPathByINode(inode: number): string {
|
|
||||||
return this._iNodeToPathString(inode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public formatPath(path: string, user: User): string {
|
|
||||||
if (path.startsWith(user.home)) return path.replace(user.home, '~');
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getNodeByInode(inode: number): TreeNode {
|
|
||||||
const node: TreeNode | undefined = this._fs.get(inode);
|
|
||||||
if (!node) throw new Error(`No node exists under inode - ${inode}`);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public resolvePath(path: string, user: User): TreeNode {
|
|
||||||
if (path === '/') return this._fs.get(this._root)!;
|
|
||||||
|
|
||||||
let parsedPath: string = path;
|
|
||||||
|
|
||||||
if (!this._isAbsolutePath(path)) {
|
|
||||||
const trail = this._iNodeToPathString(user.cwd!);
|
|
||||||
if (!trail)
|
|
||||||
throw new Error('Somehow the current user has his cwd set to a nonexistant directory', {
|
|
||||||
cause: 'iNodeToPathString returned null from user.cwd'
|
|
||||||
});
|
|
||||||
parsedPath = `${trail}/${path}`;
|
|
||||||
}
|
|
||||||
if (path.startsWith('~')) {
|
|
||||||
const trail = user.home;
|
|
||||||
if (!trail)
|
|
||||||
throw new Error('User has his home directory set to a nonexistant one or is undefined', {
|
|
||||||
cause: 'iNodeToPathString returned null from user.home'
|
|
||||||
});
|
|
||||||
parsedPath = `${trail}/${path.replace('~', '')}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._pathStringToNode(parsedPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public recursiveTraversalPre(
|
|
||||||
node: TreeNode,
|
|
||||||
callback: (param: TreeNode) => void,
|
|
||||||
childIndex?: number[],
|
|
||||||
depthIndex?: number
|
|
||||||
): void {
|
|
||||||
if (!depthIndex) depthIndex = 0;
|
|
||||||
if (!childIndex) childIndex = [0];
|
|
||||||
|
|
||||||
if (node.type != Type.File && node.children[childIndex[depthIndex]]) {
|
|
||||||
let unNode = this._fs.get(node.children[childIndex[depthIndex]]);
|
|
||||||
if (!unNode)
|
|
||||||
throw new Error(`Node does not exist under inode ${node.children[childIndex[depthIndex]]}`);
|
|
||||||
node = unNode;
|
|
||||||
|
|
||||||
depthIndex++;
|
|
||||||
if (!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
|
||||||
|
|
||||||
callback(node);
|
|
||||||
} else {
|
|
||||||
let unNode = this._fs.get(node.parent);
|
|
||||||
if (!unNode) throw new Error(`Node does not exist under inode ${node.parent}`);
|
|
||||||
node = unNode;
|
|
||||||
|
|
||||||
childIndex[depthIndex] = 0;
|
|
||||||
depthIndex--;
|
|
||||||
childIndex[depthIndex]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (depthIndex < 0) return;
|
|
||||||
|
|
||||||
this.recursiveTraversalPre(node, callback, childIndex, depthIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static get instance(): FileSystem {
|
|
||||||
if (!FileSystem.#instance) {
|
|
||||||
throw new Error(`FileSystem was not initialized properly!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FileSystem.#instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TreeNode = {
|
|
||||||
inode: number;
|
|
||||||
parent: number;
|
|
||||||
name: string;
|
|
||||||
type: Type;
|
|
||||||
size: number; //Size in Bytes
|
|
||||||
children: number[];
|
|
||||||
content: string; // GUID of the cache file that contains the file contents.
|
|
||||||
link: number; // Links
|
|
||||||
permission: NodePermission;
|
|
||||||
owner: number;
|
|
||||||
group: number;
|
|
||||||
timestamps: TimeStamps;
|
|
||||||
interactible: boolean;
|
|
||||||
func: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum Type {
|
|
||||||
Directory = 16384,
|
|
||||||
File = 32768,
|
|
||||||
SymbolicLink = 40960
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NodePermission = {
|
|
||||||
user: Permission;
|
|
||||||
group: Permission;
|
|
||||||
other: Permission;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Permission = {
|
|
||||||
r: boolean;
|
|
||||||
w: boolean;
|
|
||||||
x: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type TimeStamps = {
|
|
||||||
modified: Date;
|
|
||||||
changed: Date;
|
|
||||||
accessed: Date;
|
|
||||||
};
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
export abstract class Command {
|
|
||||||
public abstract readonly _flags: CommandFlag[];
|
|
||||||
public abstract readonly _root: boolean;
|
|
||||||
//public abstract readonly _keybinds?: Map<KeyBind, () => any>;
|
|
||||||
public abstract readonly _help: string; //TODO: Dont know where to pull the help text from yet
|
|
||||||
public abstract result: CommandResult;
|
|
||||||
|
|
||||||
public abstract Main(flags: CommandFlag[], args: string[]): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CommandFlag = {
|
|
||||||
flag: string;
|
|
||||||
values?: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CommandResult = {
|
|
||||||
bin: string;
|
|
||||||
flags?: CommandFlag[];
|
|
||||||
args?: string[];
|
|
||||||
path: number;
|
|
||||||
exitcode: ExitCode;
|
|
||||||
data?: any;
|
|
||||||
};
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import type { Command, CommandResult } from "./command";
|
|
||||||
|
|
||||||
export class Process {
|
|
||||||
private _shell: Shell;
|
|
||||||
private _uid: number;
|
|
||||||
private _name: string;
|
|
||||||
private _timestamp: Date;
|
|
||||||
//private _keybindInhibitor?: KeybindInhibitor;
|
|
||||||
private _abortController: AbortController;
|
|
||||||
private _result: CommandResult;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
bash: Shell,
|
|
||||||
uid: number,
|
|
||||||
name: string,
|
|
||||||
command: Command,
|
|
||||||
args: CommandArgs
|
|
||||||
) {
|
|
||||||
this._shell = shell;
|
|
||||||
|
|
||||||
this._uid = uid;
|
|
||||||
this._name = name;
|
|
||||||
this._timestamp = new Date();
|
|
||||||
this._abortController = new AbortController();
|
|
||||||
|
|
||||||
this._result: CommandResult = { exitCode: ExitCode.ERROR, path: this._bash.getCwd() }
|
|
||||||
|
|
||||||
if(command._keybinds) {
|
|
||||||
this._keybindInhibitor = new KeybindInhibitor(command.keybinds)
|
|
||||||
}
|
|
||||||
|
|
||||||
this._Exec(command, bash, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKeybindInhibitor(): KeybindInhibitor | null {
|
|
||||||
if(this._keybindInhibitor) return this._keybindInhibitor;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sigKill(callback: () => void): ExitCode {
|
|
||||||
this._abortController.abort();
|
|
||||||
callback();
|
|
||||||
|
|
||||||
return ExitCode.INT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Uid(): number {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Timestamp(): Date {
|
|
||||||
return this._timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Name(): string {
|
|
||||||
return this._name
|
|
||||||
}
|
|
||||||
|
|
||||||
public async get Result(): Promise<CommandResult> {
|
|
||||||
return this._result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _Exec(command: Command, shell: Shell, flags: CommandFlag[], args: string[]) {
|
|
||||||
this._result = Command.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import type { Stack } from '$lib/stores/stack';
|
|
||||||
import type { Command } from './command';
|
|
||||||
import type { Process } from './process';
|
|
||||||
|
|
||||||
export class Shell {
|
|
||||||
private _passwd: User[];
|
|
||||||
private _group: Group[];
|
|
||||||
|
|
||||||
private _commands: Command[];
|
|
||||||
|
|
||||||
private _userSessions: Stack<User>;
|
|
||||||
|
|
||||||
private user: User;
|
|
||||||
private _process?: Process;
|
|
||||||
|
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
public static Initialize(
|
|
||||||
username: string,
|
|
||||||
password: string,
|
|
||||||
commands: Map<string, Command>,
|
|
||||||
passwd: Map<number, User>,
|
|
||||||
group: Map<number, Group>
|
|
||||||
) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ExitCode {
|
|
||||||
OK = 0,
|
|
||||||
ERR = 1,
|
|
||||||
INT = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
export type User = {
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
readonly uid: number;
|
|
||||||
readonly gid: number;
|
|
||||||
home: string;
|
|
||||||
accessible: boolean;
|
|
||||||
history: string;
|
|
||||||
cwd?: number;
|
|
||||||
pwd?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Group = {
|
|
||||||
groupname: string;
|
|
||||||
gid: number;
|
|
||||||
members: number[];
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export namespace IO {
|
|
||||||
//const _io: HTMLElement = document.getElementById('output-wrapper');
|
|
||||||
|
|
||||||
export function PrintOutput(): void {}
|
|
||||||
|
|
||||||
export function ClearOutput(): void {
|
|
||||||
console.log('clear');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {};
|
|
||||||
Vendored
-239
@@ -1,239 +0,0 @@
|
|||||||
import { Shell } from "./shell/shell";
|
|
||||||
import FileSystem
|
|
||||||
|
|
||||||
|
|
||||||
export async function Initialize() {}
|
|
||||||
|
|
||||||
export const CommandRegistry: Record<string, Command> = {
|
|
||||||
cd
|
|
||||||
} as const satisfies Record<string, Command>;
|
|
||||||
|
|
||||||
export declare namespace Terminal {
|
|
||||||
async function _init() {}
|
|
||||||
|
|
||||||
export class KeybindInhibitor {
|
|
||||||
private readonly _keybinds: Map<KeyBind, () => any>;
|
|
||||||
|
|
||||||
constructor(keybinds: Map<KeyBind, () => any>) {
|
|
||||||
this._keybinds = keybinds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseModifierStates(event: KeyboardEvent): Modifier[] | undefined {
|
|
||||||
const mods: Modifier[] = [];
|
|
||||||
|
|
||||||
if (event.altKey) mods.push('Alt');
|
|
||||||
if (event.ctrlKey) mods.push('Ctrl');
|
|
||||||
if (event.shiftKey) mods.push('Ctrl');
|
|
||||||
|
|
||||||
if (mods.length == 0) return undefined;
|
|
||||||
|
|
||||||
return mods;
|
|
||||||
}
|
|
||||||
|
|
||||||
processKeystroke(event: KeyboardEvent) {
|
|
||||||
const keybind: KeyBind = [
|
|
||||||
{
|
|
||||||
key: event.key,
|
|
||||||
mods: this.parseModifierStates(event)
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const out = this._keybinds.get(keybind);
|
|
||||||
if (out) out();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Modifier = 'Ctrl' | 'Alt' | 'Shift';
|
|
||||||
|
|
||||||
type KeyStroke = {
|
|
||||||
key: string;
|
|
||||||
mods?: Modifier[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type KeyBind = [KeyStroke] | [KeyStroke, KeyStroke];
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare namespace FileSystem {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
namespace TermOS {
|
|
||||||
export async function Initialize() {}
|
|
||||||
|
|
||||||
|
|
||||||
export namespace Shell {
|
|
||||||
export class Bash {
|
|
||||||
private readonly _fs: FileSystem;
|
|
||||||
private _passwd:
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Command {
|
|
||||||
public abstract readonly FLAGS: CommandFlag[];
|
|
||||||
public abstract readonly ROOT: boolean;
|
|
||||||
public abstract readonly KEYBINDS: KeybindIn
|
|
||||||
|
|
||||||
public abstract async Main(this: Bash): Promise<CommandResult>
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Process {
|
|
||||||
|
|
||||||
private _bash: Bash;
|
|
||||||
private _result: Result;
|
|
||||||
private _uid: number;
|
|
||||||
private _name: string;
|
|
||||||
private _initTimestamp: Date;
|
|
||||||
private _keybindInhibitor?: KeybindInhibitor;
|
|
||||||
private _abortController: AbortController;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
_bashInstance: Bash,
|
|
||||||
uid: number,
|
|
||||||
name: string,
|
|
||||||
command: Command,
|
|
||||||
args: CommandArgs
|
|
||||||
) {
|
|
||||||
this._bash = _bashInstance;
|
|
||||||
this._result = { exitCode: ExitCode.ERROR, path: this._bash.getCwd() }
|
|
||||||
this._uid = uid;
|
|
||||||
this._name = name;
|
|
||||||
this._initTimestamp = new Date();
|
|
||||||
this._abortController = new AbortController();
|
|
||||||
|
|
||||||
if(command.keybinds) {
|
|
||||||
this._keybindInhibitor = new KeybindInhibitor(command.keybinds);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._Run(command, _bashInstance, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKeybindInhibitor(): KeybindInhibitor | null {
|
|
||||||
if(this._keybindInhibitor) {
|
|
||||||
return this._keybindInhibitor;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sigKill(callback: () => void): ExitCode {
|
|
||||||
this._abortController.abort();
|
|
||||||
callback();
|
|
||||||
|
|
||||||
return ExitCode.SUCCESS //Only temp, need to add ExitCode.INT
|
|
||||||
}
|
|
||||||
|
|
||||||
public getUid(): number {
|
|
||||||
return this._uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getInitTime(): Date {
|
|
||||||
return this._initTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getName(): string {
|
|
||||||
return this._name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getResult(): Promise<Result> {
|
|
||||||
return this._result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _Run(command: ICommand, bashInstance: Bash, args: CommandArgs) {
|
|
||||||
this._result = command.method.call(
|
|
||||||
bashInstance, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommandFlag = {
|
|
||||||
flag: string;
|
|
||||||
values?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ExitCode {
|
|
||||||
SUCCESS = 0,
|
|
||||||
ERROR = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommandResult = {
|
|
||||||
exit_code: ExitCode;
|
|
||||||
path: number;
|
|
||||||
data?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
type User = {
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
readonly uid: number;
|
|
||||||
readonly gid: number;
|
|
||||||
home: string;
|
|
||||||
accessible: boolean;
|
|
||||||
bash_history: string[];
|
|
||||||
cwd?: number;
|
|
||||||
pwd?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const COMMANDS
|
|
||||||
const PASSWD
|
|
||||||
const GROUP
|
|
||||||
}
|
|
||||||
class She {
|
|
||||||
private readonly _fs: FileSystem = new FileSystem();
|
|
||||||
|
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
private static async _init() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace Terminal {
|
|
||||||
export class KeybindInhibitor {
|
|
||||||
private readonly _KEYBINDS:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Terminal {
|
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
private static async _init() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FileSystem {
|
|
||||||
private _table: Map<number, TreeNode>;
|
|
||||||
|
|
||||||
constructor(fs: Map<number, TreeNode>, user: User) {}
|
|
||||||
|
|
||||||
private static async _init() {}
|
|
||||||
|
|
||||||
public type TreeNod {
|
|
||||||
inode: number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
Directory = 16384,
|
|
||||||
File = 32768,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type NodePermission = {
|
|
||||||
user: Permission;
|
|
||||||
group: Permission;
|
|
||||||
other: Permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Finish this
|
|
||||||
enum ExitCode {
|
|
||||||
SUCCESS = 0,
|
|
||||||
ERROR = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
type Permission = {
|
|
||||||
r: boolean;
|
|
||||||
w: boolean;
|
|
||||||
x: boolean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
export class MD5 {
|
|
||||||
private static encoder: TextEncoder = new TextEncoder();
|
|
||||||
|
|
||||||
// prettier-ignore
|
|
||||||
private static K: number[] = [
|
|
||||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
|
||||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
|
||||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
|
||||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
|
||||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
|
||||||
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
|
||||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
|
||||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
|
||||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
|
||||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
|
||||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
|
||||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
|
||||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
|
||||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
|
||||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
|
||||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
|
||||||
];
|
|
||||||
|
|
||||||
// prettier-ignore
|
|
||||||
private static S: number[] = [
|
|
||||||
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
|
||||||
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
|
||||||
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
|
||||||
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
|
|
||||||
];
|
|
||||||
|
|
||||||
public static hash(input: string) {
|
|
||||||
const inputArr: Uint8Array<ArrayBuffer> = this.encoder.encode(input);
|
|
||||||
const padded = MD5.pad(inputArr);
|
|
||||||
|
|
||||||
let A = 0x67452301;
|
|
||||||
let B = 0xefcdab89;
|
|
||||||
let C = 0x98badcfe;
|
|
||||||
let D = 0x10325476;
|
|
||||||
|
|
||||||
function processBlock(M: number[]) {
|
|
||||||
function F(b: number, c: number, d: number): number {
|
|
||||||
return (b & c) | (~b & d);
|
|
||||||
}
|
|
||||||
function H(b: number, c: number, d: number): number {
|
|
||||||
return b ^ c ^ d;
|
|
||||||
}
|
|
||||||
function I(b: number, c: number, d: number): number {
|
|
||||||
return c ^ (b | ~d);
|
|
||||||
}
|
|
||||||
function G(b: number, c: number, d: number): number {
|
|
||||||
return (b & d) | (c & ~d);
|
|
||||||
}
|
|
||||||
|
|
||||||
let AA = A,
|
|
||||||
BB = B,
|
|
||||||
CC = C,
|
|
||||||
DD = D;
|
|
||||||
|
|
||||||
for (let i = 0; i < 64; i++) {
|
|
||||||
let f: number, g: number;
|
|
||||||
|
|
||||||
if (i < 16) {
|
|
||||||
f = F(B, C, D);
|
|
||||||
g = i;
|
|
||||||
} else if (i < 32) {
|
|
||||||
f = G(B, C, D);
|
|
||||||
g = (5 * i + 1) % 16;
|
|
||||||
} else if (i < 48) {
|
|
||||||
f = H(B, C, D);
|
|
||||||
g = (3 * i + 5) % 16;
|
|
||||||
} else {
|
|
||||||
f = I(B, C, D);
|
|
||||||
g = (7 * i) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sum = MD5.add32(A, MD5.add32(f, MD5.add32(M[g], MD5.K[i])));
|
|
||||||
const temp = MD5.add32(B, MD5.leftRotate(sum, MD5.S[i]));
|
|
||||||
|
|
||||||
A = D;
|
|
||||||
D = C;
|
|
||||||
C = B;
|
|
||||||
B = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
A = MD5.add32(A, AA);
|
|
||||||
B = MD5.add32(B, BB);
|
|
||||||
C = MD5.add32(C, CC);
|
|
||||||
D = MD5.add32(D, DD);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < padded.length; i += 64) {
|
|
||||||
const M = MD5.sliceToWords(padded.slice(i, i + 64));
|
|
||||||
processBlock(M); // modifies A, B, C, D directly
|
|
||||||
}
|
|
||||||
|
|
||||||
const hashBytes = new Uint8Array([
|
|
||||||
...MD5.wordToBytesLE(A),
|
|
||||||
...MD5.wordToBytesLE(B),
|
|
||||||
...MD5.wordToBytesLE(C),
|
|
||||||
...MD5.wordToBytesLE(D)
|
|
||||||
]);
|
|
||||||
|
|
||||||
return MD5.toHexString(hashBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static pad(input: Uint8Array): Uint8Array {
|
|
||||||
const inputBitLength: number = input.length * 8;
|
|
||||||
|
|
||||||
const out: Uint8Array = new Uint8Array([...input, 0x80]);
|
|
||||||
const NBytes: number = (56 - (out.length % 64) + 64) % 64;
|
|
||||||
|
|
||||||
const zeroArray = new Uint8Array(NBytes);
|
|
||||||
|
|
||||||
const low = inputBitLength >>> 0;
|
|
||||||
const high = (inputBitLength / 0x100000000) >>> 0;
|
|
||||||
|
|
||||||
const lengthBytes = new Uint8Array([
|
|
||||||
low & 0xff,
|
|
||||||
(low >> 8) & 0xff,
|
|
||||||
(low >> 16) & 0xff,
|
|
||||||
(low >> 24) & 0xff,
|
|
||||||
high & 0xff,
|
|
||||||
(high >> 8) & 0xff,
|
|
||||||
(high >> 16) & 0xff,
|
|
||||||
(high >> 24) & 0xff
|
|
||||||
]);
|
|
||||||
|
|
||||||
return new Uint8Array([...out, ...zeroArray, ...lengthBytes]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static sliceToBlocks(input: Uint8Array): number[][] {
|
|
||||||
const blocks: number[][] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i += 64) {
|
|
||||||
const block = input.slice(i, i + 64);
|
|
||||||
blocks.push(MD5.sliceToWords(block));
|
|
||||||
}
|
|
||||||
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static sliceToWords(block: Uint8Array): number[] {
|
|
||||||
const words: number[] = new Array<number>(16);
|
|
||||||
|
|
||||||
for (let i = 0; i < 16; i++) {
|
|
||||||
const offset: number = i * 4;
|
|
||||||
|
|
||||||
words[i] =
|
|
||||||
(block[offset] |
|
|
||||||
(block[offset + 1] << 8) |
|
|
||||||
(block[offset + 2] << 16) |
|
|
||||||
(block[offset + 3] << 24)) >>>
|
|
||||||
0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return words;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static leftRotate(x: number, n: number): number {
|
|
||||||
x = x >>> 0;
|
|
||||||
return ((x << n) | (x >>> (32 - n))) >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static add32(a: number, b: number): number {
|
|
||||||
return ((a >>> 0) + (b >>> 0)) >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static wordToBytesLE(word: number): Uint8Array {
|
|
||||||
return new Uint8Array([
|
|
||||||
word & 0xff,
|
|
||||||
(word >>> 8) & 0xff,
|
|
||||||
(word >>> 16) & 0xff,
|
|
||||||
(word >>> 24) & 0xff
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static toHexString(bytes: Uint8Array): string {
|
|
||||||
return Array.from(bytes)
|
|
||||||
.map((b) => b.toString(16).padStart(2, '0'))
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
import { FileSystem, type TreeNode } from '../filesystem/filesystem';
|
|
||||||
|
|
||||||
export enum SortNodeBy {
|
|
||||||
NAME = 'name',
|
|
||||||
INODE = 'inode',
|
|
||||||
SIZE = 'size',
|
|
||||||
EXTENSION = 'extension',
|
|
||||||
TYPE = 'type',
|
|
||||||
MTIME = 'modified',
|
|
||||||
ATIME = 'accessed',
|
|
||||||
CTIME = 'changed'
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Sort {
|
|
||||||
public static nodeArraySort(
|
|
||||||
nodes: TreeNode[] | number[],
|
|
||||||
reverse: boolean = false,
|
|
||||||
sortBy: SortNodeBy = SortNodeBy.NAME
|
|
||||||
): TreeNode[] {
|
|
||||||
if (nodes.length === 0) {
|
|
||||||
console.warn('Tried to sort an empty node array!');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const parsedNodes: TreeNode[] = [];
|
|
||||||
|
|
||||||
if (typeof nodes[0] === 'number') {
|
|
||||||
for (const inode of nodes as number[]) {
|
|
||||||
const node = FileSystem.instance.getNodeByInode(inode);
|
|
||||||
parsedNodes.push(node);
|
|
||||||
}
|
|
||||||
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
|
||||||
console.log(parsedNodes);
|
|
||||||
return parsedNodes;
|
|
||||||
} else {
|
|
||||||
Sort.nodeQSort(nodes as TreeNode[], reverse, sortBy, 0, nodes.length - 1);
|
|
||||||
console.log(nodes);
|
|
||||||
return nodes as TreeNode[];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static nodeQSort(
|
|
||||||
array: TreeNode[],
|
|
||||||
reverse: boolean,
|
|
||||||
sortBy: SortNodeBy,
|
|
||||||
start: number,
|
|
||||||
end: number
|
|
||||||
) {
|
|
||||||
if (end <= start) return;
|
|
||||||
|
|
||||||
let pivot: number = this.nodePartition(array, reverse, sortBy, start, end);
|
|
||||||
this.nodeQSort(array, reverse, sortBy, start, pivot - 1);
|
|
||||||
this.nodeQSort(array, reverse, sortBy, pivot + 1, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static nodePartition(
|
|
||||||
part: TreeNode[],
|
|
||||||
reverse: boolean,
|
|
||||||
sortBy: SortNodeBy,
|
|
||||||
start: number,
|
|
||||||
end: number
|
|
||||||
): number {
|
|
||||||
let pivot: TreeNode = part[end];
|
|
||||||
let i: number = start - 1;
|
|
||||||
|
|
||||||
for (let j = start; j <= end; j++) {
|
|
||||||
if (this.nodeCompareElements(part[j], pivot, sortBy, reverse) < 0) {
|
|
||||||
i++;
|
|
||||||
let temp = part[i];
|
|
||||||
part[i] = part[j];
|
|
||||||
part[j] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
let temp = part[i];
|
|
||||||
part[i] = part[end];
|
|
||||||
part[end] = temp;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static nodeCompareElements(
|
|
||||||
a: TreeNode,
|
|
||||||
b: TreeNode,
|
|
||||||
sortBy: SortNodeBy,
|
|
||||||
reverse: boolean
|
|
||||||
): number {
|
|
||||||
switch (sortBy) {
|
|
||||||
case SortNodeBy.NAME: {
|
|
||||||
const nameA: string = a.name.startsWith('.') ? a.name.slice(1) : a.name;
|
|
||||||
const nameB: string = b.name.startsWith('.') ? b.name.slice(1) : b.name;
|
|
||||||
const minLength = Math.min(nameA.length, nameB.length);
|
|
||||||
|
|
||||||
for (let i = 0; i < minLength; i++) {
|
|
||||||
const charCodeA = Posix.GetCharWeight(nameA[i]);
|
|
||||||
const charCodeB = Posix.GetCharWeight(nameB[i]);
|
|
||||||
|
|
||||||
if (charCodeA !== charCodeB) {
|
|
||||||
return reverse ? charCodeB - charCodeA : charCodeA - charCodeB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return reverse ? nameB.length - nameA.length : nameA.length - nameB.length;
|
|
||||||
}
|
|
||||||
case SortNodeBy.MTIME:
|
|
||||||
case SortNodeBy.ATIME:
|
|
||||||
case SortNodeBy.CTIME: {
|
|
||||||
console.log(sortBy, 'sortby');
|
|
||||||
// The sortBy serves as the lookup key in the timestamps object.
|
|
||||||
// It works because the times in SortBy enum have assigned values matching the names of the keys in the TreeNode object
|
|
||||||
const timeA: number = a.timestamps[sortBy].getTime();
|
|
||||||
const timeB: number = b.timestamps[sortBy].getTime();
|
|
||||||
|
|
||||||
return reverse ? timeA - timeB : timeB - timeA;
|
|
||||||
}
|
|
||||||
case SortNodeBy.SIZE: {
|
|
||||||
return reverse ? a.size - b.size : b.size - a.size;
|
|
||||||
}
|
|
||||||
case SortNodeBy.EXTENSION: {
|
|
||||||
const extA: string = a.name.split('.').pop() ?? '';
|
|
||||||
const extB: string = b.name.split('.').pop() ?? '';
|
|
||||||
const minLength = Math.min(extA.length, extB.length);
|
|
||||||
|
|
||||||
for (let i = 0; i < minLength; i++) {
|
|
||||||
const charCodeA = extA.charCodeAt(i);
|
|
||||||
const charCodeB = extB.charCodeAt(i);
|
|
||||||
|
|
||||||
if (charCodeA !== charCodeB) {
|
|
||||||
return reverse ? charCodeB - charCodeA : charCodeA - charCodeB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return reverse ? extB.length - extA.length : extA.length - extB.length;
|
|
||||||
}
|
|
||||||
case SortNodeBy.INODE: {
|
|
||||||
return reverse ? b.inode - a.inode : a.inode - b.inode;
|
|
||||||
}
|
|
||||||
case SortNodeBy.TYPE: {
|
|
||||||
return reverse ? b.type - a.type : a.type - b.type;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new Error(`Sorting basis outside of the declared scope. - `);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Posix {
|
|
||||||
private static readonly CharTable = {
|
|
||||||
// Space and punctuation (32-47)
|
|
||||||
' ': 32,
|
|
||||||
'!': 33,
|
|
||||||
'"': 34,
|
|
||||||
'#': 35,
|
|
||||||
$: 36,
|
|
||||||
'%': 37,
|
|
||||||
'&': 38,
|
|
||||||
"'": 39,
|
|
||||||
'(': 40,
|
|
||||||
')': 41,
|
|
||||||
'*': 42,
|
|
||||||
'+': 43,
|
|
||||||
',': 44,
|
|
||||||
'-': 45,
|
|
||||||
'.': 46,
|
|
||||||
'/': 47,
|
|
||||||
|
|
||||||
// Numbers 0-9 (48-57)
|
|
||||||
'0': 48,
|
|
||||||
'1': 49,
|
|
||||||
'2': 50,
|
|
||||||
'3': 51,
|
|
||||||
'4': 52,
|
|
||||||
'5': 53,
|
|
||||||
'6': 54,
|
|
||||||
'7': 55,
|
|
||||||
'8': 56,
|
|
||||||
'9': 57,
|
|
||||||
|
|
||||||
// More punctuation (58-64)
|
|
||||||
':': 58,
|
|
||||||
';': 59,
|
|
||||||
'<': 60,
|
|
||||||
'=': 61,
|
|
||||||
'>': 62,
|
|
||||||
'?': 63,
|
|
||||||
'@': 64,
|
|
||||||
|
|
||||||
// LETTERS - INTERLEAVED AaBbCc... (65-116)
|
|
||||||
A: 65,
|
|
||||||
a: 66,
|
|
||||||
B: 67,
|
|
||||||
b: 68,
|
|
||||||
C: 69,
|
|
||||||
c: 70,
|
|
||||||
D: 71,
|
|
||||||
d: 72,
|
|
||||||
E: 73,
|
|
||||||
e: 74,
|
|
||||||
F: 75,
|
|
||||||
f: 76,
|
|
||||||
G: 77,
|
|
||||||
g: 78,
|
|
||||||
H: 79,
|
|
||||||
h: 80,
|
|
||||||
I: 81,
|
|
||||||
i: 82,
|
|
||||||
J: 83,
|
|
||||||
j: 84,
|
|
||||||
K: 85,
|
|
||||||
k: 86,
|
|
||||||
L: 87,
|
|
||||||
l: 88,
|
|
||||||
M: 89,
|
|
||||||
m: 90,
|
|
||||||
N: 91,
|
|
||||||
n: 92,
|
|
||||||
O: 93,
|
|
||||||
o: 94,
|
|
||||||
P: 95,
|
|
||||||
p: 96,
|
|
||||||
Q: 97,
|
|
||||||
q: 98,
|
|
||||||
R: 99,
|
|
||||||
r: 100,
|
|
||||||
S: 101,
|
|
||||||
s: 102,
|
|
||||||
T: 103,
|
|
||||||
t: 104,
|
|
||||||
U: 105,
|
|
||||||
u: 106,
|
|
||||||
V: 107,
|
|
||||||
v: 108,
|
|
||||||
W: 109,
|
|
||||||
w: 110,
|
|
||||||
X: 111,
|
|
||||||
x: 112,
|
|
||||||
Y: 113,
|
|
||||||
y: 114,
|
|
||||||
Z: 115,
|
|
||||||
z: 116,
|
|
||||||
|
|
||||||
// Specials after letters (now 117-126)
|
|
||||||
'[': 117,
|
|
||||||
'\\': 118,
|
|
||||||
']': 119,
|
|
||||||
'^': 120,
|
|
||||||
_: 121,
|
|
||||||
'`': 122,
|
|
||||||
'{': 123,
|
|
||||||
'|': 124,
|
|
||||||
'}': 125,
|
|
||||||
'~': 126
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
public static GetCharWeight(char: string): number {
|
|
||||||
return this.CharTable[char as keyof typeof this.CharTable];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,286 +0,0 @@
|
|||||||
class Vector2 {
|
|
||||||
public x: number;
|
|
||||||
public y: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
*/
|
|
||||||
constructor(x?: number, y?: number);
|
|
||||||
constructor(v?: Vector2);
|
|
||||||
constructor(x: Vector2 | number = 0, y: number = 0) {
|
|
||||||
if (typeof x === 'object' && x !== null) {
|
|
||||||
this.x = x.x;
|
|
||||||
this.y = x.y;
|
|
||||||
} else {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add(s: number): Vector2;
|
|
||||||
add(v: Vector2): Vector2;
|
|
||||||
add(arg: number | Vector2): Vector2 {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
return new Vector2(this.x + arg, this.y + arg);
|
|
||||||
} else {
|
|
||||||
return new Vector2(this.x + arg.x, this.y + arg.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub(s: number): Vector2;
|
|
||||||
sub(v: Vector2): Vector2;
|
|
||||||
sub(arg: number | Vector2): Vector2 {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
return new Vector2(this.x - arg, this.y - arg);
|
|
||||||
} else {
|
|
||||||
return new Vector2(this.x - arg.x, this.y - arg.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mul(s: number): Vector2;
|
|
||||||
mul(v: Vector2): Vector2;
|
|
||||||
mul(arg: number | Vector2): Vector2 {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
return new Vector2(this.x * arg, this.y * arg);
|
|
||||||
} else {
|
|
||||||
return new Vector2(this.x * arg.x, this.y * arg.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
div(s: number): Vector2;
|
|
||||||
div(v: Vector2): Vector2;
|
|
||||||
div(arg: number | Vector2): Vector2 {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
return new Vector2(this.x / arg, this.y / arg);
|
|
||||||
} else {
|
|
||||||
return new Vector2(this.x / arg.x, this.y / arg.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
equals(v: Vector2, epsilon: number = 1e-10): boolean {
|
|
||||||
return Math.abs(this.x - v.x) < epsilon && Math.abs(this.y - v.y) < epsilon;
|
|
||||||
}
|
|
||||||
|
|
||||||
get sqrLength(): number {
|
|
||||||
return this.x * this.x + this.y * this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
get length(): number {
|
|
||||||
return Math.sqrt(this.sqrLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
get normalized(): Vector2 {
|
|
||||||
const len = this.length;
|
|
||||||
return len === 0 ? new Vector2(0, 0) : new Vector2(this.x / len, this.y / len);
|
|
||||||
}
|
|
||||||
|
|
||||||
get angle(): number {
|
|
||||||
return Math.atan2(this.y, this.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
addEq(s: number): this;
|
|
||||||
addEq(v: Vector2): this;
|
|
||||||
addEq(arg: number | Vector2): this {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
this.x += arg;
|
|
||||||
this.y += arg;
|
|
||||||
} else {
|
|
||||||
this.x += arg.x;
|
|
||||||
this.y += arg.y;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
subEq(s: number): this;
|
|
||||||
subEq(v: Vector2): this;
|
|
||||||
subEq(arg: number | Vector2): this {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
this.x -= arg;
|
|
||||||
this.y -= arg;
|
|
||||||
} else {
|
|
||||||
this.x -= arg.x;
|
|
||||||
this.y -= arg.y;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
mulEq(s: number): this;
|
|
||||||
mulEq(v: Vector2): this;
|
|
||||||
mulEq(arg: number | Vector2): this {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
this.x *= arg;
|
|
||||||
this.y *= arg;
|
|
||||||
} else {
|
|
||||||
this.x *= arg.x;
|
|
||||||
this.y *= arg.y;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
divEq(s: number): this;
|
|
||||||
divEq(v: Vector2): this;
|
|
||||||
divEq(arg: number | Vector2): this {
|
|
||||||
if (typeof arg === 'number') {
|
|
||||||
this.x /= arg;
|
|
||||||
this.y /= arg;
|
|
||||||
} else {
|
|
||||||
this.x /= arg.x;
|
|
||||||
this.y /= arg.y;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
cross(v: Vector2): number {
|
|
||||||
return this.x * v.y - this.y * v.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
dot(v: Vector2): number {
|
|
||||||
return this.x * v.x + this.y * v.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
set(x: number, y: number): this {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
normalize(): this {
|
|
||||||
const len = this.length;
|
|
||||||
if (len !== 0) {
|
|
||||||
this.x /= len;
|
|
||||||
this.y /= len;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
get perpendicular(): Vector2 {
|
|
||||||
return new Vector2(-this.y, this.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
clone(): Vector2 {
|
|
||||||
return new Vector2(this.x, this.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
return `Vector2(${this.x}, ${this.y})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
toArray(): [number, number] {
|
|
||||||
return [this.x, this.y];
|
|
||||||
}
|
|
||||||
|
|
||||||
[Symbol.iterator](): Iterator<number> {
|
|
||||||
let index = 0;
|
|
||||||
const components = [this.x, this.y];
|
|
||||||
return {
|
|
||||||
next: (): IteratorResult<number> => {
|
|
||||||
if (index < components.length) {
|
|
||||||
return { value: components[index++], done: false };
|
|
||||||
} else {
|
|
||||||
return { value: undefined as any, done: true };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this.xy below threshold, if so - set to 0 (each param individually)
|
|
||||||
* @param {number} Deadzone treshold e.g. 1-4e (0.{4 - 0's}1)
|
|
||||||
* @returns {this} new Vector2 with values of this or 0
|
|
||||||
* @example
|
|
||||||
* // sets this.x or this.y to 0 if less then 0.0000001
|
|
||||||
* vecFoo.deadZone(1e-6);
|
|
||||||
*/
|
|
||||||
deadZone(threshold: number = 1e-4): Vector2 {
|
|
||||||
return new Vector2(
|
|
||||||
Math.abs(this.x) < threshold ? 0 : this.x,
|
|
||||||
Math.abs(this.y) < threshold ? 0 : this.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if *this*xy below threshold, if so - set to 0 (each param individually)
|
|
||||||
* @param {number} Deadzone treshold e.g. 1-4e (0.{4 - 0's}1)
|
|
||||||
* @returns {Vector2} this - i.e. the vector that calls the method.
|
|
||||||
* @example
|
|
||||||
* // sets this.x or this.y to 0 if less then 0.0000001
|
|
||||||
* vecFoo.deadZone(1e-6);
|
|
||||||
*/
|
|
||||||
deadZoneEq(threshold: number = 1e-4): this {
|
|
||||||
if (Math.abs(this.x) < threshold) this.x = 0;
|
|
||||||
if (Math.abs(this.y) < threshold) this.y = 0;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
static fromAngle(angle: number, magnitude: number = 1): Vector2 {
|
|
||||||
return new Vector2(Math.cos(angle) * magnitude, Math.sin(angle) * magnitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
static dot(a: Vector2, b: Vector2): number {
|
|
||||||
return a.x * b.x + a.y * b.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static cross(a: Vector2, b: Vector2): number {
|
|
||||||
return a.x * b.y - a.y * b.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static distance(a: Vector2, b: Vector2): number {
|
|
||||||
const dx = a.x - b.x;
|
|
||||||
const dy = a.y - b.y;
|
|
||||||
return Math.sqrt(dx * dx + dy * dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
static distanceSqr(a: Vector2, b: Vector2): number {
|
|
||||||
const dx = a.x - b.x;
|
|
||||||
const dy = a.y - b.y;
|
|
||||||
return dx * dx + dy * dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
static lerp(a: Vector2, b: Vector2, t: number): Vector2 {
|
|
||||||
return new Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
|
|
||||||
}
|
|
||||||
|
|
||||||
static clamp(v: Vector2, min: Vector2, max: Vector2): Vector2 {
|
|
||||||
return new Vector2(
|
|
||||||
Math.min(Math.max(v.x, min.x), max.x),
|
|
||||||
Math.min(Math.max(v.y, min.y), max.y)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static angleBetween(a: Vector2, b: Vector2): number {
|
|
||||||
const dot = Vector2.dot(a, b);
|
|
||||||
const mag = a.length * b.length;
|
|
||||||
if (mag === 0) return 0;
|
|
||||||
|
|
||||||
const cos = dot / mag;
|
|
||||||
return Math.acos(Math.min(1, Math.max(-1, cos)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static get zero(): Vector2 {
|
|
||||||
return new Vector2(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get one(): Vector2 {
|
|
||||||
return new Vector2(1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get up(): Vector2 {
|
|
||||||
return new Vector2(0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get down(): Vector2 {
|
|
||||||
return new Vector2(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get left(): Vector2 {
|
|
||||||
return new Vector2(-1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get right(): Vector2 {
|
|
||||||
return new Vector2(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Vector2;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import Vector2 from "./vector";
|
|
||||||
|
|
||||||
class VMath {
|
|
||||||
|
|
||||||
public static toRadians(angle: number): number {
|
|
||||||
return angle * (Math.PI / 180);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static rotate(vec: Vector2, angle: number, origin: Vector2): void {
|
|
||||||
const x: number = vec.x - origin.x;
|
|
||||||
const y: number = vec.y - origin.y;
|
|
||||||
|
|
||||||
const cos: number = Math.cos(this.toRadians(angle));
|
|
||||||
const sin: number = Math.sin(this.toRadians(angle));
|
|
||||||
|
|
||||||
let xPrim: number = (x * cos) - (y * sin);
|
|
||||||
let yPrim: number = (x * sin) + (y * cos);
|
|
||||||
xPrim += origin.x;
|
|
||||||
yPrim += origin.y;
|
|
||||||
|
|
||||||
vec.set(xPrim, yPrim);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static compare(x: number, y: number): boolean;
|
|
||||||
public static compare(vec1: Vector2, vec2: Vector2): boolean;
|
|
||||||
public static compare(arg1: Vector2 | number, arg2: Vector2 | number): boolean {
|
|
||||||
if(typeof arg1 === 'number' && typeof arg2 === 'number')
|
|
||||||
return Math.abs(arg1 - arg2) <= Number.MIN_VALUE * Math.max(1, Math.abs(arg1), Math.abs(arg2));
|
|
||||||
else if (typeof arg1 !== 'number' && typeof arg2 !== 'number')
|
|
||||||
return Math.abs(arg1.x - arg2.x) <= Number.MIN_VALUE * Math.max(1, Math.abs(arg1.x), Math.abs(arg2.x)) &&
|
|
||||||
Math.abs(arg1.y - arg2.y) <= Number.MIN_VALUE * Math.max(1, Math.abs(arg1.y), Math.abs(arg2.y))
|
|
||||||
else {
|
|
||||||
throw new Error('unexpected usage of compare method in vmath library');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default VMath;
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { enhance } from "$app/forms";
|
|
||||||
import { PASSWD } from "$lib/stores/bash/etc/userData";
|
|
||||||
import { ArrowRight, ChevronLeft, ChevronRight, CircleAlert, Lock } from "@lucide/svelte";
|
|
||||||
import type { effect } from "zod/v3";
|
|
||||||
|
|
||||||
|
|
||||||
let formElem: HTMLElement;
|
|
||||||
let {init, form}: { init: (formData: FormData) => void, form: any} = $props();
|
|
||||||
|
|
||||||
const USERS = PASSWD.filter((user) => user.accesible == true);
|
|
||||||
const basePath: string = '/src/lib/assets/login/';
|
|
||||||
|
|
||||||
let userIndex: number = $state(3);
|
|
||||||
let username: string = $state('gornodox');
|
|
||||||
|
|
||||||
function changeUser(direction: 0 | 1) {
|
|
||||||
if(direction === 0) userIndex--;
|
|
||||||
else userIndex++;
|
|
||||||
|
|
||||||
if(userIndex >= USERS.length) userIndex = 0;
|
|
||||||
if(userIndex < 0) userIndex = USERS.length - 1;
|
|
||||||
|
|
||||||
const user = USERS[userIndex];
|
|
||||||
username = user.username;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div id="wrapper" class=" flex flex-col items-center" class:outro={form?.success}>
|
|
||||||
<img class="rounded-full mb-4 border-primary-dark border-2" src={`${basePath}${username}.png`} onerror={(event) => {(event.currentTarget as HTMLImageElement).src = `${basePath}default.png`; return false;}} alt="user avatar" width="80" height="80" />
|
|
||||||
<div id="name" class=" relative flex flex-row items-center text-text-muted-dark justify-center gap-4 w-1/2">
|
|
||||||
<button onclick={() => changeUser(0)}
|
|
||||||
class=" active:-translate-x-0.5 hover:text-primary-hover-dark"><ChevronLeft size={16} strokeWidth={2} /></button>
|
|
||||||
<strong class=" mx-auto">{username}</strong>
|
|
||||||
<button onclick={() => changeUser(1)}
|
|
||||||
class=" active:translate-x-0.5 hover:text-primary-hover-dark"><ChevronRight size={16} strokeWidth={2} /></button>
|
|
||||||
</div>
|
|
||||||
<form bind:this={formElem} onanimationend={() => {formElem.classList.remove('invalid')}} use:enhance={({ formData }) =>
|
|
||||||
{
|
|
||||||
init(formData);
|
|
||||||
}
|
|
||||||
} method="POST" action="?/login" class:invalid={form?.error} name="login-form" autocomplete="off" class="mt-6 flex flex-row gap-1">
|
|
||||||
<input name="username" value={username} class=" hidden ">
|
|
||||||
<div class=" bg-bg-lighter-dark flex flex-row ml-4 items-center rounded outline-none border border-transparent text-sm p-1.5 w-2xs text-text-dark focus-within:bg-bg-light-dark focus-within:border-primary-dark {form?.error ? 'focus-within:border-warning-dark text-warning-dark' : ''}">
|
|
||||||
<Lock size={16} strokeWidth={2} />
|
|
||||||
<input autofocus name="password" type="password" autocomplete="off" placeholder="Password..." class=" placeholder-text-dark {form?.error ? 'placeholder-warning-dark' : ''} grow ml-2 appearance-none outline-none">
|
|
||||||
</div>
|
|
||||||
<button type="submit" class=" bg-bg-lighter-dark rounded p-1.5 hover:text-primary-hover-dark active:text-primary-dark active:bg-bg-light-dark">
|
|
||||||
<ArrowRight size={20} strokeWidth={2} />
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.invalid {
|
|
||||||
animation: var(--animate-error-shake);
|
|
||||||
}
|
|
||||||
|
|
||||||
#error {
|
|
||||||
animation: fadeIn 0.2s forwards cubic-bezier(.4,.7,0,.99);
|
|
||||||
}
|
|
||||||
|
|
||||||
.switchL {
|
|
||||||
animation: fadeSlideLeft .75s forwards cubic-bezier(.4,.7,0,.99);
|
|
||||||
}
|
|
||||||
|
|
||||||
.switchR {
|
|
||||||
animation: fadeSlideRight .75s forwards cubic-bezier(.4,.7,0,.99);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@keyframes fadeSlideLeft {
|
|
||||||
25% {
|
|
||||||
transform: translateX(-1rem);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
transform: translateX(1rem);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
75% {
|
|
||||||
transform: none;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeSlideRight {
|
|
||||||
25% {
|
|
||||||
transform: translateX(1rem);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
transform: translateX(-1rem);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: none;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeIn {
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.outro {
|
|
||||||
transition: opacity 0.5s cubic-bezier(.4,.7,0,.99) 1s;
|
|
||||||
opacity: 0;
|
|
||||||
form {
|
|
||||||
transition: opacity 0.2s cubic-bezier(.4,.7,0,.99);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
img {
|
|
||||||
transform: translateY(30px) scale(1.2);
|
|
||||||
transition: transform 0.5s ease-out;
|
|
||||||
}
|
|
||||||
#name {
|
|
||||||
transform: translateY(30px);
|
|
||||||
transition: transform 0.5s ease-out;
|
|
||||||
}
|
|
||||||
#error {
|
|
||||||
transition: opacity 0.2s cubic-bezier(.4,.7,0,.99);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<div class=" w-dvw h-dvh">
|
|
||||||
<div class=" select-none font-primary m-[10%] flex flex-col items-start " id="wrapper">
|
|
||||||
<h1 class=" text-primary-dark font-semibold text-4xl mb-7" id="">Strona w konserwacji</h1>
|
|
||||||
<p class=" text-text-muted-dark text-2xl my-5" id="">Strona jest obecnie w konserwacji. Przepraszam za niedogodność, wkrótce będzie dostępna</p>
|
|
||||||
<p class=" text-text-muted-dark text-2xl self-center mt-16 mb-5" id="">Jeżeli uważasz że jest to błąd, proszę skontaktuj się ze mną
|
|
||||||
<a id="click" class="relative" href="mailto:biznes.olszewski@gmail.com?subject=Website/Portfolio under maintenance">tutaj</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
#click {
|
|
||||||
color: var(--color-primary-dark);
|
|
||||||
pointer-events: all;
|
|
||||||
user-select: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
#click::after {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
bottom: 0;
|
|
||||||
height: 1px;
|
|
||||||
width: calc(100% + 1vw);
|
|
||||||
background: linear-gradient(90deg, var(--color-primary-dark) 75%, transparent 100%);
|
|
||||||
transform: scaleX(0);
|
|
||||||
transform-origin: left;
|
|
||||||
transition: transform 0.1s cubic-bezier(.8,.6,.85,.7);
|
|
||||||
}
|
|
||||||
#click:hover::after {
|
|
||||||
transform: scaleX(1);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Languages, Settings2, SunMoon } from '@lucide/svelte';
|
import { Languages, Settings2, SunMoon } from '@lucide/svelte';
|
||||||
import { theme } from '$lib/stores/theme';
|
import { theme } from '$lib/stores/theme';
|
||||||
import { locale } from '$lib/stores/lang';
|
|
||||||
import plFlag from '$lib/assets/plFlag.svg';
|
import plFlag from '$lib/assets/plFlag.svg';
|
||||||
import enFlag from '$lib/assets/enFlag.svg';
|
import enFlag from '$lib/assets/enFlag.svg';
|
||||||
import deFlag from '$lib/assets/deFlag.svg';
|
import deFlag from '$lib/assets/deFlag.svg';
|
||||||
@@ -19,15 +18,11 @@
|
|||||||
const langsMenu = window.document.getElementById('langs-menu');
|
const langsMenu = window.document.getElementById('langs-menu');
|
||||||
langsMenu?.classList.toggle('hide');
|
langsMenu?.classList.toggle('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLang(id: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="options"
|
id="options"
|
||||||
class=" z-100 absolute top-0 left-0 isolate mx-4 rounded-b-xl bg-bg-dark light:bg-bg-light"
|
class="absolute top-0 left-0 isolate mx-4 rounded-b-xl bg-bg-dark light:bg-bg-light"
|
||||||
>
|
>
|
||||||
<section class="hide grid" id="settings-menu">
|
<section class="hide grid" id="settings-menu">
|
||||||
<div class="flex flex-col items-center justify-center gap-4 overflow-hidden">
|
<div class="flex flex-col items-center justify-center gap-4 overflow-hidden">
|
||||||
@@ -55,31 +50,29 @@
|
|||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="pl-PL" autocomplete="off" onclick={() => {console.log($locale)}}/>
|
<input name="langs" type="radio" class="lang hidden" id="pl" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={plFlag} alt="PL" height="26" width="26" />
|
<img class="flags mx-2" src={plFlag} alt="PL" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en-US" autocomplete="off" onclick={(id) => {
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
console.log(id);
|
|
||||||
}}/>
|
|
||||||
<img class="flags mx-2" src={enFlag} alt="EN" height="26" width="26" />
|
<img class="flags mx-2" src={enFlag} alt="EN" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="fr-FR" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={deFlag} alt="DE" height="26" width="26" />
|
<img class="flags mx-2" src={deFlag} alt="DE" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={jaFlag} alt="JA" height="26" width="26" />
|
<img class="flags mx-2" src={jaFlag} alt="JA" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark transition-none duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={frFlag} alt="FR" height="26" width="26" />
|
<img class="flags mx-2" src={frFlag} alt="FR" height="26" width="26" />
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import Renderer from '$lib/shimagic/renderer/rendererr';
|
|
||||||
import { WebG } from '$lib/shimagic/renderer/web_g_enginee';
|
|
||||||
import { Shimagic } from '$lib/stores/shimeji';
|
|
||||||
import Vector2 from '$lib/vector';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
const drag: number = 3;
|
|
||||||
const speed: number = 2;
|
|
||||||
|
|
||||||
let shimeji: Shimagic.Shimeji;
|
|
||||||
let renderer: Renderer;
|
|
||||||
let sprite: HTMLElement;
|
|
||||||
let canvas: HTMLCanvasElement;
|
|
||||||
let shown: boolean = $state(false);
|
|
||||||
|
|
||||||
function genRandomPos(min: number, max: number): number {
|
|
||||||
const out = Math.random() * (max - min) + min;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchShader(path: string): Promise<string> {
|
|
||||||
const response = await fetch(path);
|
|
||||||
if (!response.ok) throw new Error(`failed to fetch the shader file ${response}`);
|
|
||||||
return await response.text();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
canvas.width = window.innerWidth;
|
|
||||||
canvas.height = window.innerHeight;
|
|
||||||
|
|
||||||
//const vert = await fetchShader('src/lib/shimeji/renderer/shaders/vertex_shader.vert');
|
|
||||||
//const frag = await fetchShader('src/lib/shimeji/renderer/shaders/fragment_shader.frag');
|
|
||||||
|
|
||||||
const engineConfig: WebG.EngineConfig = {
|
|
||||||
canvas: canvas,
|
|
||||||
vertexShaderUrl: 'src/lib/shimeji/renderer/shaders/vertex_shader.vert',
|
|
||||||
fragmentShaderUrl: 'src/lib/shimeji/renderer/shaders/fragment_shader.frag',
|
|
||||||
attributes: {
|
|
||||||
aPosition: 0,
|
|
||||||
aColor: 1
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const engine = await WebG.Engine.Initialize(engineConfig);
|
|
||||||
|
|
||||||
const drawArgs: WebG.DrawCallArgs = {
|
|
||||||
vertices: [
|
|
||||||
new Vector2(200, 200),
|
|
||||||
new Vector2(700, 700),
|
|
||||||
new Vector2(700, 200),
|
|
||||||
new Vector2(200, 200),
|
|
||||||
new Vector2(200, 700),
|
|
||||||
new Vector2(700, 700)
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
engine.setDrawMode(WebG.EngineDrawMode.TEXTURE);
|
|
||||||
engine.draw(drawArgs);
|
|
||||||
|
|
||||||
/* shimeji = new Shimeji(40, canvas, renderer);
|
|
||||||
shimeji.start();
|
|
||||||
|
|
||||||
shown = true;
|
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key === 'a') {
|
|
||||||
shimeji.addImpulse(-500, -100);
|
|
||||||
}
|
|
||||||
if (e.key === 'd') {
|
|
||||||
shimeji.addImpulse(500, -100);
|
|
||||||
}
|
|
||||||
if (e.key === 'space') {
|
|
||||||
shimeji.moveTo(genRandomPos(200, window.innerWidth - 200));
|
|
||||||
}
|
|
||||||
}); */
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class=" absolute z-20 size-full overflow-clip">
|
|
||||||
<canvas
|
|
||||||
bind:this={canvas}
|
|
||||||
style=" stroke-width: 5px;"
|
|
||||||
class=" absolute z-2 size-full stroke-red-500"
|
|
||||||
></canvas>
|
|
||||||
<!-- <div
|
|
||||||
bind:this={sprite}
|
|
||||||
class=" absolute z-30 size-20 origin-center -translate-1/2 cursor-grab bg-amber-400 opacity-15 will-change-transform transform-flat"
|
|
||||||
></div> -->
|
|
||||||
</div>
|
|
||||||
+40
-60
@@ -1,65 +1,44 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ExitCode } from '$lib/stores/bash/metadata';
|
import type { User } from '$lib/stores/bash/bash';
|
||||||
import { initTerminal } from '$lib/stores/terminal/init.svelte';
|
|
||||||
import { clear, print } from '$lib/stores/terminal/stdio/io';
|
|
||||||
import { Terminal, type PrintData } from '$lib/stores/terminal/terminal';
|
import { Terminal, type PrintData } from '$lib/stores/terminal/terminal';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
import Input from './terminal/Input.svelte';
|
import Input from './terminal/Input.svelte';
|
||||||
|
import { initTerminal, isInitializing } from '$lib/stores/terminal/init.svelte';
|
||||||
|
import { clear, print } from '$lib/stores/terminal/stdio';
|
||||||
|
|
||||||
const clearTerminal = (): void => clear();
|
const clearTerminal = (): void => clear();
|
||||||
|
|
||||||
const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
||||||
|
|
||||||
export async function init(username: string, password: string) {
|
|
||||||
try {
|
|
||||||
terminal = await initTerminal({ username, password }, callbackInit, 'en_US');
|
|
||||||
updateTerminal();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('terminal init failed', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
runTerminal();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTerminal() {
|
function updateTerminal() {
|
||||||
//isProcessActive = terminal.isProcessActive;
|
|
||||||
username = terminal!.getUser().username;
|
username = terminal!.getUser().username;
|
||||||
cwd = terminal!.getCwd();
|
cwd = terminal!.getCwd();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWidth() {
|
function getWidth() {
|
||||||
const e = document.getElementById('cout');
|
const e = document.getElementById('cout');
|
||||||
if (!e) {
|
if(!e){
|
||||||
throw new Error('cant get width of the teminal element. Its null');
|
throw new Error('cant get width of the teminal element. Its null');
|
||||||
}
|
}
|
||||||
//gets an int from padding property value (which is a string) by cutting last 2 letters "px" and parsing to int
|
//gets an int from padding property value (which is a string) by cutting last 2 letters "px" and parsing to int
|
||||||
const padding: number = parseInt(
|
const padding: number = parseInt(window.getComputedStyle(e, null).getPropertyValue('padding').slice(0, -2));
|
||||||
window.getComputedStyle(e, null).getPropertyValue('padding').slice(0, -2)
|
return e.clientWidth - (padding * 2);
|
||||||
);
|
|
||||||
return e.clientWidth - padding * 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFontSize() {
|
function getFontSize() {
|
||||||
const e = document.getElementById('cout');
|
return 10;
|
||||||
if (!e) {
|
/* const e = document.getElementById('cout');
|
||||||
|
if(!e) {
|
||||||
throw new Error('cant get font size of the terminal element. its null');
|
throw new Error('cant get font size of the terminal element. its null');
|
||||||
}
|
}
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d')!;
|
const ctx = canvas.getContext('2d')!;
|
||||||
ctx.font = `${window.getComputedStyle(e, null).getPropertyValue('font-size')} 'JetBrains Mono', monospace;`;
|
ctx.font = `${window.getComputedStyle(e, null).getPropertyValue('font-size')} 'JetBrains Mono', monospace;`;
|
||||||
return ctx.measureText('M').width;
|
return ctx.measureText(' ').width; */
|
||||||
}
|
}
|
||||||
|
|
||||||
function inputHandler(event: KeyboardEvent) {
|
function handleInput(event: KeyboardEvent) {
|
||||||
const terminalKeyInhibitor = terminal.getKeybindInhibitor();
|
|
||||||
terminalKeyInhibitor.processKeystroke(event);
|
|
||||||
|
|
||||||
const processKeyInhibitor = terminal.getProcessKeyInhibitor();
|
|
||||||
if (processKeyInhibitor != ExitCode.ERROR) {
|
|
||||||
processKeyInhibitor.processKeystroke(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(processKeyInhibitor, terminalKeyInhibitor);
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'Enter': {
|
case 'Enter': {
|
||||||
terminal.executeCommand(inputValue);
|
terminal.executeCommand(inputValue);
|
||||||
@@ -81,17 +60,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const elem = document.getElementById('cout');
|
const elem = document.getElementById('cout');
|
||||||
if (!elem) {
|
if(!elem){
|
||||||
throw new Error('cant scroll to bottom, element is null');
|
throw new Error('cant scroll to bottom, element is null');
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.scrollTop = elem.scrollHeight;
|
elem.scrollTop = elem.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTerminal() {
|
|
||||||
document.getElementById('terminal-window')?.classList.remove('hidden');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Callback initializer
|
//Callback initializer
|
||||||
const callbackInit = {
|
const callbackInit = {
|
||||||
print: (data: any) => {
|
print: (data: any) => {
|
||||||
@@ -99,25 +74,40 @@
|
|||||||
if (!e) return;
|
if (!e) return;
|
||||||
printOutput(e, data);
|
printOutput(e, data);
|
||||||
},
|
},
|
||||||
clear: clearTerminal,
|
clear: clear,
|
||||||
getWidth: getWidth,
|
getWidth: getWidth,
|
||||||
getFontSize: getFontSize
|
getFontSize: getFontSize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Test user with basic data so the bash can run
|
||||||
|
let testUser: User = {
|
||||||
|
username: 'kamil',
|
||||||
|
passwd: '123',
|
||||||
|
uid: 0,
|
||||||
|
gid: 0,
|
||||||
|
home: '/home/kamil',
|
||||||
|
history: []
|
||||||
|
};
|
||||||
|
|
||||||
//Empty terminal variable where the terminal class instance will be stored
|
//Empty terminal variable where the terminal class instance will be stored
|
||||||
let terminal: Terminal;
|
let terminal: Terminal;
|
||||||
let username: string = $state('');
|
let username: string = $state(testUser.username);
|
||||||
let cwd: string = $state('');
|
let cwd: string = $state(testUser.home);
|
||||||
//let isProcessActive = $state(false);
|
|
||||||
|
|
||||||
let inputValue = $state<string>('');
|
let inputValue = $state<string>('');
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
try {
|
||||||
|
terminal = await initTerminal(testUser, callbackInit);
|
||||||
|
updateTerminal();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('onMount trycatch failed', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label for="input" onkeydowncapture={(event) => inputHandler(event)} class="w-11/12">
|
<label for="input" onkeydowncapture={(e) => handleInput(e)} class="w-11/12">
|
||||||
<div
|
<div id="terminal" class="terminal-window shadow-() h-full w-full rounded-md shadow-bg">
|
||||||
id="terminal"
|
|
||||||
class=" terminal-window shadow-() h-full w-full rounded-md shadow-bg transition-discrete"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-bg-dark text-center font-terminal text-sm font-bold text-primary-dark light:bg-bg-dark-light light:text-primary-light"
|
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-bg-dark text-center font-terminal text-sm font-bold text-primary-dark light:bg-bg-dark-light light:text-primary-light"
|
||||||
>
|
>
|
||||||
@@ -126,7 +116,7 @@
|
|||||||
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
||||||
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
||||||
</div>
|
</div>
|
||||||
<div class=" mr-2 flex grow">
|
<div class=" flex mr-2 grow">
|
||||||
<h5>{username}</h5>
|
<h5>{username}</h5>
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
<h5 class=" mr-2">@terminal: </h5>
|
<h5 class=" mr-2">@terminal: </h5>
|
||||||
@@ -147,16 +137,6 @@
|
|||||||
* {
|
* {
|
||||||
transition: var(--transition-standard);
|
transition: var(--transition-standard);
|
||||||
}
|
}
|
||||||
@keyframes fadeIn {
|
|
||||||
from {
|
|
||||||
opacity: 0;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.dots-wrapper {
|
.dots-wrapper {
|
||||||
& > button {
|
& > button {
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { Type } from '$lib/termos/filesystem/filesystem';
|
|
||||||
import { File, Folder } from '@lucide/svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
nodeName,
|
|
||||||
nodeType,
|
|
||||||
isProject = true
|
|
||||||
}: { nodeName: string; nodeType: Type; isProject: boolean } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class=" flex flex-row items-center rounded-md bg-bg-lighter-dark p-2">
|
|
||||||
{#if nodeType == Type.Directory}
|
|
||||||
<Folder class="text-primary-dark" strokeWidth={1} />
|
|
||||||
{:else}
|
|
||||||
<File strokeWidth={1} />
|
|
||||||
{/if}
|
|
||||||
<h4 class={isProject ? 'text-primary-dark' : 'text-text-dark'}>{nodeName}</h4>
|
|
||||||
</div>
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let { projectName, checked = true }: { projectName: string; checked: boolean } = $props();
|
import { ChevronRight, Power, SquarePen } from '@lucide/svelte';
|
||||||
|
|
||||||
|
let { projectName, checked = true }: { projectName: string; checked?: boolean } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class=" flex items-center text-text-dark saturate-50 has-checked:saturate-100 light:text-text-light"
|
class=" flex items-center text-text-dark saturate-50 has-checked:saturate-100 light:text-text-light"
|
||||||
>
|
>
|
||||||
<div class=" flex w-48 flex-col justify-center gap-1 rounded-lg bg-bg-mid-dark">
|
<div class=" flex w-full flex-col justify-center gap-1 rounded-lg bg-bg-mid-dark">
|
||||||
<h5 class=" m-4 font-primary text-xl font-bold">{projectName}</h5>
|
<h5 class=" m-4 font-primary text-xl font-bold">{projectName}</h5>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<label
|
<label
|
||||||
|
|||||||
@@ -8,26 +8,10 @@
|
|||||||
function handleInput(event: Event) {
|
function handleInput(event: Event) {
|
||||||
inputValue = (event.target as HTMLInputElement).value;
|
inputValue = (event.target as HTMLInputElement).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function moveCursor() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function keyDown(event: KeyboardEvent) {
|
|
||||||
switch(event.key) {
|
|
||||||
case 'Enter':
|
|
||||||
inputValue = ''
|
|
||||||
case 'ArrowRight':
|
|
||||||
document.getElementById('cursor')?.style.transform = 'translateX(8px)'
|
|
||||||
case 'ArrowLeft':
|
|
||||||
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class=" relative">
|
<div class=" relative">
|
||||||
<input
|
<input
|
||||||
autofocus
|
|
||||||
bind:value={inputValue}
|
bind:value={inputValue}
|
||||||
onkeydown={(e) => e.key === 'Enter' && (inputValue = '')}
|
onkeydown={(e) => e.key === 'Enter' && (inputValue = '')}
|
||||||
oninput={handleInput}
|
oninput={handleInput}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
|
||||||
import { theme } from '$lib/stores/theme';
|
|
||||||
import { onMount, type Snippet } from 'svelte';
|
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
//import Loading from '../modules/Loading.svelte';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
//import Shimeji from '../modules/Shimeji.svelte';
|
import { onMount, type Snippet } from 'svelte';
|
||||||
|
import { theme } from '$lib/stores/theme';
|
||||||
|
|
||||||
let { children }: { children: Snippet } = $props();
|
let { children }: { children: Snippet } = $props();
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { db } from "$lib/server/db";
|
|
||||||
import { settings } from "$lib/server/db/schema";
|
|
||||||
import { PASSWD } from "$lib/stores/bash/etc/userData";
|
|
||||||
import { eq } from "drizzle-orm";
|
|
||||||
import type { Actions } from "./$types";
|
|
||||||
import type { PageServerLoad } from "./panel/projects/$types";
|
|
||||||
|
|
||||||
export const actions = {
|
|
||||||
login: async ({request}) => {
|
|
||||||
const user = PASSWD.find((object) => object.username == "gornodox");
|
|
||||||
let data = await request.formData();
|
|
||||||
let out = data.get("password")?.toString();
|
|
||||||
let error = false;
|
|
||||||
let success = true
|
|
||||||
|
|
||||||
if(out != user?.passwd || out == undefined) {
|
|
||||||
error = true;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { error, success, data: out };
|
|
||||||
}
|
|
||||||
} satisfies Actions
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
|
||||||
return {
|
|
||||||
settings: await db.select({setting: settings.state}).from(settings).where(eq(settings.var, 'maintenance')).limit(1)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
+6
-65
@@ -1,73 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import TerminalModule from '../modules/Terminal.svelte';
|
||||||
import Settings from '../modules/Settings.svelte';
|
import Settings from '../modules/Settings.svelte';
|
||||||
|
import Loading from '../modules/Loading.svelte';
|
||||||
import { isInitializing } from '$lib/stores/terminal/init.svelte';
|
import { isInitializing } from '$lib/stores/terminal/init.svelte';
|
||||||
import Login from '../modules/Login.svelte';
|
|
||||||
import { mount } from 'svelte';
|
|
||||||
import Terminal from '../modules/Terminal.svelte';
|
|
||||||
import { CircleAlert } from '@lucide/svelte';
|
|
||||||
import Maintenence from '../modules/Maintenence.svelte';
|
|
||||||
|
|
||||||
let { form, data } = $props();
|
|
||||||
|
|
||||||
const MAINTENANCE = $derived(Boolean(data.settings[0].setting));
|
|
||||||
|
|
||||||
//export let isWelcomeSequence = false;
|
|
||||||
|
|
||||||
// svelte-ignore non_reactive_update
|
|
||||||
let terminalComponent: Terminal;
|
|
||||||
|
|
||||||
function welcomeSequence() {
|
|
||||||
//isWelcomeSequence = true;
|
|
||||||
|
|
||||||
//TODO: do magic :)
|
|
||||||
}
|
|
||||||
|
|
||||||
function initializer(formData: FormData) {
|
|
||||||
console.log(formData);
|
|
||||||
|
|
||||||
if(form?.error) return;
|
|
||||||
const password = formData.get("password")?.toString();
|
|
||||||
const username = formData.get("username")?.toString();
|
|
||||||
if(!password || !username) throw new Error("password or username is null or undefined");
|
|
||||||
terminalComponent.init(username, password)
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if MAINTENANCE}
|
<Settings></Settings>
|
||||||
<Settings></Settings>
|
<div class="h-dvh w-full p-24 flex justify-center">
|
||||||
<Maintenence />
|
<TerminalModule />
|
||||||
{:else}
|
</div>
|
||||||
<Settings></Settings>
|
|
||||||
<div id="main" class="h-dvh w-full p-24 relative flex justify-center items-center">
|
|
||||||
<div id="wrapper1" class=" absolute z-35 flex flex-col items-center {form?.success ? 'outro' : ''}">
|
|
||||||
<Login init={initializer} form={form}/>
|
|
||||||
</div>
|
|
||||||
<div id="wrapper2" class=" opacity-0 size-4/5 absolute z-4 {form?.success ? 'intro' : ''}">
|
|
||||||
<Terminal bind:this={terminalComponent} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.intro {
|
|
||||||
animation: fadeIn 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.outro {
|
|
||||||
animation: fadeOut 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeIn {
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeOut {
|
|
||||||
to {
|
|
||||||
opacity: 0;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { db } from '$lib/server/db';
|
|
||||||
import { filesystem } from '$lib/server/db/schema';
|
|
||||||
import { MD5 } from '$lib/termos/util/hash';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
|
|
||||||
export async function GET({ request }): Promise<Response> {
|
|
||||||
const row = await db
|
|
||||||
.select({
|
|
||||||
data: filesystem.data,
|
|
||||||
checksum: filesystem.checksum
|
|
||||||
})
|
|
||||||
.from(filesystem)
|
|
||||||
.where(eq(filesystem.id, 1))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!row.length) {
|
|
||||||
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, checksum } = row[0];
|
|
||||||
const clientETag = request.headers.get('if-none-match');
|
|
||||||
|
|
||||||
if (clientETag === `"${checksum}"`) {
|
|
||||||
return new Response(null, {
|
|
||||||
status: 304,
|
|
||||||
headers: { ETag: `"${checksum}"` }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(data, {
|
|
||||||
status: 200,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
ETag: `"${checksum}"`,
|
|
||||||
'Cache-Control': 'no-cache'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST({ request }) {
|
|
||||||
const newData = await request.text();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(newData);
|
|
||||||
//TODO: Schema validation
|
|
||||||
} catch {
|
|
||||||
//TODO: Change that to a proper http headers error
|
|
||||||
return new Response(null, {
|
|
||||||
status: 400
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const checksum: string = MD5.hash(newData);
|
|
||||||
|
|
||||||
await db.update(filesystem).set({ data: newData, checksum }).where(eq(filesystem.id, 1));
|
|
||||||
|
|
||||||
return new Response(JSON.stringify({ success: true }), { status: 200 });
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { db } from '$lib/server/db';
|
|
||||||
import { users } from '$lib/server/db/schema';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
|
|
||||||
export async function GET({ request }): Promise<Response> {
|
|
||||||
const rows = await db
|
|
||||||
.select({
|
|
||||||
uid: users.uid,
|
|
||||||
username: users.username,
|
|
||||||
password: users.password,
|
|
||||||
home: users.home,
|
|
||||||
gid: users.gid,
|
|
||||||
accessible: users.accessible
|
|
||||||
})
|
|
||||||
.from(users);
|
|
||||||
|
|
||||||
if (!rows.length) {
|
|
||||||
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: {}[] = rows.map((u) => ({
|
|
||||||
...u,
|
|
||||||
avatarUrl: `/api/users/${u.uid}/avatar`
|
|
||||||
}));
|
|
||||||
|
|
||||||
return json(result);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { db } from '$lib/server/db';
|
|
||||||
import { users } from '$lib/server/db/schema';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
|
|
||||||
export async function GET({ params, request }): Promise<Response> {
|
|
||||||
const row = await db
|
|
||||||
.select({
|
|
||||||
uid: users.uid,
|
|
||||||
username: users.username,
|
|
||||||
password: users.password,
|
|
||||||
home: users.home,
|
|
||||||
gid: users.gid,
|
|
||||||
accessible: users.accessible
|
|
||||||
})
|
|
||||||
.from(users)
|
|
||||||
.where(eq(users.uid, Number(params.uid)))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!row.length) {
|
|
||||||
return new Response(`User not found`, { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = row[0];
|
|
||||||
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({
|
|
||||||
...user,
|
|
||||||
avatarUrl: `/api/users/${user.uid}/avatar`
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { db } from '$lib/server/db';
|
|
||||||
import { users } from '$lib/server/db/schema';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
|
|
||||||
export async function PUT({ params, request }) {
|
|
||||||
const uid = Number(params.uid);
|
|
||||||
const arrayBuffer = await request.arrayBuffer();
|
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
|
||||||
await db.update(users).set({ face: buffer }).where(eq(users.uid, uid));
|
|
||||||
return new Response(null, { status: 204 });
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
|
||||||
import { BookA, ChartLine, ChartNoAxesColumn, FolderArchive, Plus } from '@lucide/svelte';
|
|
||||||
import { type Snippet } from 'svelte';
|
|
||||||
import '../../app.css';
|
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';
|
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
||||||
let { children, data }: { children: Snippet; data: any } = $props();
|
|
||||||
|
let { children }: { children: Snippet } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class=" w-full">
|
<div class="flex w-full grow">
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { db } from '$lib/server/db';
|
|
||||||
import { locales } from '$lib/server/db/schema';
|
|
||||||
import type { PageServerLoad } from './$types';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
|
||||||
return {
|
|
||||||
locales: await db
|
|
||||||
.select({
|
|
||||||
code: locales.code,
|
|
||||||
name: locales.name,
|
|
||||||
dictionary: locales.dictionary,
|
|
||||||
flag: locales.flag,
|
|
||||||
enabled: locales.enabled
|
|
||||||
})
|
|
||||||
.from(locales)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,25 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import LangModule from '../../../modules/panel/LangModule.svelte';
|
import LangModule from '../../../modules/panel/LangModule.svelte';
|
||||||
|
import plFlag from '$lib/assets/plFlag.svg';
|
||||||
let { data }: { data: any } = $props();
|
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>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<form name="locales" class="m-10 flex flex-col gap-4">
|
<form name="langs" class="m-10 flex flex-col gap-4">
|
||||||
{#each data.locales as locale}
|
<LangModule checked langName="Polish" icon={plFlag} />
|
||||||
<LangModule checked={locale.enabled} langName={locale.name} icon={locale.flag} />
|
|
||||||
{/each}
|
|
||||||
<!-- <LangModule checked langName="Polish" icon={plFlag} />
|
|
||||||
<LangModule checked langName="English" icon={enFlag} />
|
<LangModule checked langName="English" icon={enFlag} />
|
||||||
<LangModule checked langName="German" icon={deFlag} />
|
<LangModule checked langName="German" icon={deFlag} />
|
||||||
<LangModule langName="Japanese" icon={jaFlag} />
|
<LangModule langName="Japanese" icon={jaFlag} />
|
||||||
<LangModule langName="French" icon={frFlag} /> -->
|
<LangModule langName="French" icon={frFlag} />
|
||||||
</form>
|
</form>
|
||||||
<div>
|
<div></div>
|
||||||
<form>
|
|
||||||
<input type="file" />
|
|
||||||
<input type="image" alt="NaN" />
|
|
||||||
<input type="text" />
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
import fsData from '$lib/assets/fs/fs.json';
|
|
||||||
import { db } from '$lib/server/db';
|
|
||||||
import { projects, settings } from '$lib/server/db/schema';
|
|
||||||
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
|
||||||
import { Sort, SortNodeBy } from '$lib/termos/util/sort';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
import type { PageServerLoad } from './$types';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
|
||||||
FileSystem.Init(fsData as any);
|
|
||||||
|
|
||||||
const fs = FileSystem.instance;
|
|
||||||
|
|
||||||
const node = fs.getNodeByInode(13); //Gordonox home dir
|
|
||||||
let nodes = node.children.map((child) => fs.getNodeByInode(child));
|
|
||||||
nodes = Sort.nodeArraySort(nodes, false, SortNodeBy.NAME);
|
|
||||||
|
|
||||||
return {
|
|
||||||
settings: await db
|
|
||||||
.select({ setting: settings.state })
|
|
||||||
.from(settings)
|
|
||||||
.where(eq(settings.var, 'maintenance'))
|
|
||||||
.limit(1),
|
|
||||||
projects: await db
|
|
||||||
.select({
|
|
||||||
id: projects.id,
|
|
||||||
name: projects.name,
|
|
||||||
data: projects.data,
|
|
||||||
enabled: projects.enabled
|
|
||||||
})
|
|
||||||
.from(projects),
|
|
||||||
nodes: nodes
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,78 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Construction, Eye, EyeOff } from '@lucide/svelte';
|
|
||||||
import NodeModule from '../../../modules/panel/NodeModule.svelte';
|
|
||||||
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
||||||
import { setMaintenanceState } from '../settings.remote';
|
|
||||||
|
|
||||||
let { data }: { data: any } = $props();
|
|
||||||
|
|
||||||
let maintenance = $state(Boolean(data.settings[0].setting));
|
|
||||||
let showHidden = $state(false);
|
|
||||||
|
|
||||||
console.log(data.projects[0].name);
|
|
||||||
|
|
||||||
function handleToggle() {
|
|
||||||
console.log(maintenance);
|
|
||||||
maintenance = !maintenance;
|
|
||||||
console.log(maintenance);
|
|
||||||
let result = setMaintenanceState(Number(maintenance) as 1 | 0);
|
|
||||||
console.log(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleHidden() {
|
|
||||||
showHidden = !showHidden;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class=" m-10">
|
||||||
class=" grid-cols-[1.5fr, 1fr] grid w-full"
|
<ProjectModule projectName="ProjectName" />
|
||||||
style="grid-template-areas:
|
|
||||||
'a b'; "
|
|
||||||
>
|
|
||||||
<div class=" m-10">
|
|
||||||
{#each data.projects as project}
|
|
||||||
<ProjectModule projectName={project.name} checked={project.enabled} />
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="m-8 flex w-xl flex-col justify-self-end">
|
|
||||||
<div>
|
|
||||||
<button title="ButtonShowHidden" onclick={toggleHidden}>
|
|
||||||
{#if !showHidden}
|
|
||||||
<EyeOff stroke-width={1} class="text-text-muted-dark" />
|
|
||||||
{:else}
|
|
||||||
<Eye stroke-width={1} />
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class=" flex flex-col gap-1">
|
|
||||||
{#each data.nodes as node}
|
|
||||||
{#if showHidden}
|
|
||||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
|
||||||
{/if}
|
|
||||||
{#if !node.name.startsWith('.') && !showHidden}
|
|
||||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class=" mt-4">
|
|
||||||
<Construction strokeWidth={1} />
|
|
||||||
<label
|
|
||||||
for="maintenence"
|
|
||||||
class="relative m-2 ml-auto block h-5 w-10 cursor-pointer rounded-full bg-bg-lighter-dark shadow-subtle"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={maintenance}
|
|
||||||
onclick={async () => await setMaintenanceState(Number(!maintenance))}
|
|
||||||
id="maintenence"
|
|
||||||
class=" peer sr-only"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
class=" absolute top-0.5 left-0.5 h-4/5 w-2/5 rounded-full bg-bg-dark peer-checked:left-5.5 peer-checked:bg-primary-dark"
|
|
||||||
>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import { query } from '$app/server';
|
|
||||||
import { db } from '$lib/server/db';
|
|
||||||
import { settings } from '$lib/server/db/schema';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
import z from 'zod';
|
|
||||||
|
|
||||||
export const setMaintenanceState = query(z.number(), async (state) => {
|
|
||||||
await db.update(settings).set({ state }).where(eq(settings.var, 'maintenance'));
|
|
||||||
});
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { MD5 } from '$lib/termos/util/hash';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
console.log(MD5.hash(''));
|
|
||||||
console.log(MD5.hash('a'));
|
|
||||||
console.log(MD5.hash('abc'));
|
|
||||||
|
|
||||||
onMount(() => {});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
@theme {
|
@theme {
|
||||||
--animate-loading: loading 1s ease-in-out infinite;
|
--animate-loading: loading 1s ease-in-out infinite;
|
||||||
--animate-cursor-blink: blink 1s step-end infinite;
|
--animate-cursor-blink: blink 1s step-end infinite;
|
||||||
--animate-error-shake: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
|
|
||||||
|
|
||||||
@keyframes blink {
|
@keyframes blink {
|
||||||
0% {
|
0% {
|
||||||
@@ -24,19 +23,4 @@
|
|||||||
transform: scaleY(1);
|
transform: scaleY(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes shake {
|
|
||||||
10%, 90% {
|
|
||||||
transform: translate3d(-1px, 0, 0);
|
|
||||||
}
|
|
||||||
20%, 80% {
|
|
||||||
transform: translate3d(2px, 0, 0);
|
|
||||||
}
|
|
||||||
30%, 50%, 70% {
|
|
||||||
transform: translate3d(-4px, 0, 0);
|
|
||||||
}
|
|
||||||
40%, 60% {
|
|
||||||
transform: translate3d(4px, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
@custom-variant light (&:where(.light, .light *));
|
@custom-variant light (&:where(.light, .light *));
|
||||||
|
|
||||||
* {
|
* {
|
||||||
/* transition: all 0.2s ease-in allow-discrete; */
|
transition: all 0.2s ease-in allow-discrete;
|
||||||
}
|
}
|
||||||
|
|
||||||
@utility scroll-hidden {
|
@utility scroll-hidden {
|
||||||
|
|||||||
@@ -8,17 +8,9 @@ const config = {
|
|||||||
preprocess: vitePreprocess(),
|
preprocess: vitePreprocess(),
|
||||||
|
|
||||||
kit: {
|
kit: {
|
||||||
experimental: {
|
|
||||||
remoteFunctions: true
|
|
||||||
}
|
|
||||||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
||||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||||
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
||||||
},
|
|
||||||
compilerOptions: {
|
|
||||||
experimental: {
|
|
||||||
async: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user