Compare commits

...

2 Commits

10 changed files with 5409 additions and 2 deletions

View File

@ -34,13 +34,14 @@
pkgs.libadwaita
pkgs.librsvg
pkgs.nodejs
pkgs.nodePackages.eslint
pkgs.nodePackages.typescript
pkgs.nodePackages.typescript-language-server
pkgs.openssl
pkgs.pipewire
pkgs.pkg-config
pkgs.rustup
pkgs.sqlite
pkgs.cargo-nextest
pkgs.wasm-pack
pkgs.sqlx-cli
pkgs.udev
pkgs.wasm-pack

10
otg/pwa/.eslintrc.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
env: {
node: true,
jest: true,
},
extends: ['plugin:@typescript-eslint/recommended', 'eslint:recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
}

5
otg/pwa/jest.config.js Normal file
View File

@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

5210
otg/pwa/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
otg/pwa/package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "otg-pwa",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"lint": "eslint ./src/**/.ts",
"test": "jest",
"test:watch": "jest --watch"
},
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
"license": "GPL-3.0-or-later",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"http-server": "^14.1.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.3"
}
}

View File

@ -0,0 +1,37 @@
import { c_to_k, f_to_k, k_to_c, k_to_f } from './conversions';
describe('temperature conversions', () => {
it('should convert celsius to kelvin', () => {
expect(c_to_k(0)).toBe(273.15);
expect(c_to_k(100)).toBe(373.15);
});
it('should convert fahrenheit to kelvin', () => {
expect(f_to_k(32)).toBe(273.15);
expect(f_to_k(212)).toBe(373.15);
});
it('should convert kelvin to celsius', () => {
expect(k_to_c(273.15)).toBe(0);
expect(k_to_c(373.15)).toBe(100);
});
it('should convert kelvin to fahrenheit', () => {
expect(k_to_f(273.15)).toBe(32);
expect(k_to_f(373.15)).toBe(212);
});
});
/*
import { getMessage } from './index'
describe('getMessage()', () => {
it('should return the correct message when called', () => {
expect(getMessage()).toBe('Hello, world')
})
it('should be super smart', () => {
expect(true).toBe(true)
})
})
*/

View File

@ -0,0 +1,6 @@
export const c_to_k = (value: number) => value + 273.15;
export const f_to_k = (value: number) => ((value - 32) * 5 / 9) + 273.15;
export const k_to_c = (value: number) => value - 273.15;
export const k_to_f = (value: number) => (value - 273.15) * 9 / 5 + 32;

18
otg/pwa/src/index.html Normal file
View File

@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>On The Grid</title>
<style>
:body {
font-family: "sans-serif";
}
</style>
</head>
<body>
<div id="app"></div>
<script type="module" src="./index.js"></script>
</body>
</html>

83
otg/pwa/src/index.ts Normal file
View File

@ -0,0 +1,83 @@
import { c_to_k, f_to_k, k_to_c, k_to_f } from './conversions';
interface TemperatureChanged {
source: string,
value: number,
}
class TemperatureField extends HTMLElement {
static observedAttributes = ['value'];
value = 0;
inputElement: HTMLInputElement;
shadow: ShadowRoot;
constructor() {
super();
this.inputElement = document.createElement('input');
this.inputElement.type = "text";
this.shadow = this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.render();
this.inputElement.onchange = ev => {
if (ev.target instanceof HTMLInputElement) {
let value = parseFloat(ev.target.value);
if (this.id == "f") {
const event = new CustomEvent('temperature-changed', { detail: { source: this.id, value: f_to_k(value) } });
this.dispatchEvent(event);
} else if (this.id == "c") {
const event = new CustomEvent('temperature-changed', { detail: { source: this.id, value: c_to_k(value) } });
this.dispatchEvent(event);
} else if (this.id == "k") {
const event = new CustomEvent('temperature-changed', { detail: { source: this.id, value } });
this.dispatchEvent(event);
}
}
}
}
render() {
this.shadow.appendChild(this.inputElement);
}
setTemperature(v: number) {
console.log("set the temperature on ", this.id, "to ", v);
}
}
class App {
temperatureK = 0;
updateTemperature(value: number) {
const f = document.getElementById("f");
if (f instanceof TemperatureField) {
f.setTemperature(value);
}
const c = document.getElementById("c");
if (c instanceof TemperatureField) {
c.setTemperature(value);
}
const k = document.getElementById("k");
if (k instanceof TemperatureField) {
k.setTemperature(value);
}
}
}
window.customElements.define('temperature-field', TemperatureField);
const app = new App();
document.getElementById("f")?.addEventListener('temperature-changed', ev => {
if (ev instanceof CustomEvent) { app.updateTemperature(ev.detail.value) }
});
document.getElementById("c")?.addEventListener('temperature-changed', ev => {
if (ev instanceof CustomEvent) { app.updateTemperature(ev.detail.value) }
});
document.getElementById("k")?.addEventListener('temperature-changed', ev => {
if (ev instanceof CustomEvent) { app.updateTemperature(ev.detail.value) }
});

13
otg/pwa/tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}