From 44ea9cae00066d02371f5cc8c74f9920682d0ff7 Mon Sep 17 00:00:00 2001 From: William Moore Date: Sun, 12 May 2024 17:21:30 -0500 Subject: [PATCH] Updates --- package-lock.json | 43 ++++++++++----------------- package.json | 7 +++-- public/affirmations.html | 2 +- public/rainfall.html | 2 +- public/rss.html | 2 +- public/splork.html | 2 +- public/time.html | 10 +++++++ public/weather.html | 2 +- src/Affirmations.ts | 4 +-- src/RSS.ts | 4 +-- src/Rainfall.ts | 12 +++----- src/Splork.ts | 4 +-- src/Time.ts | 64 ++++++++++++++++++++++++++++++++++++++++ src/Weather.ts | 6 ++-- 14 files changed, 111 insertions(+), 53 deletions(-) create mode 100644 public/time.html create mode 100644 src/Time.ts diff --git a/package-lock.json b/package-lock.json index 84961db..c645203 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "date-fns": "^2.30.0", + "date-fns": "^3.0.0", + "date-fns-tz": "^3.1.3", "dotenv": "^16.1.4", "lit": "^2.7.5", "typescript": "^5.1.3" @@ -280,22 +281,6 @@ "node": ">=6.0.0" } }, - "node_modules/@babel/runtime": { - "version": "7.23.8", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.8.tgz", - "integrity": "sha512-Y7KbAP984rn1VGMbGqKmBLio9V7y5Je9GvU4rQPCPinCyNfUcToxIXl06d59URp/F3LwinvODxab5N/G6qggkw==", - "dependencies": { - "regenerator-runtime": "^0.14.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/runtime/node_modules/regenerator-runtime": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" - }, "node_modules/@babel/template": { "version": "7.22.15", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", @@ -1813,18 +1798,20 @@ } }, "node_modules/date-fns": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", - "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", - "dependencies": { - "@babel/runtime": "^7.21.0" - }, - "engines": { - "node": ">=0.11" - }, + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz", + "integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==", "funding": { - "type": "opencollective", - "url": "https://opencollective.com/date-fns" + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" + } + }, + "node_modules/date-fns-tz": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-3.1.3.tgz", + "integrity": "sha512-ZfbMu+nbzW0mEzC8VZrLiSWvUIaI3aRHeq33mTe7Y38UctKukgqPR4nTDwcwS4d64Gf8GghnVsroBuMY3eiTeA==", + "peerDependencies": { + "date-fns": "^3.0.0" } }, "node_modules/debug": { diff --git a/package.json b/package.json index 10f0752..b96a4d3 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,20 @@ { - "name": "lavender", + "name": "mosaic-widgets", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "npm run build && npm run deploy", "build": "npx tsc && cp -R public dist && npx gulp && npx rollup -c", - "deploy": "rm -rf ~/www/html/lavender-widgets && cp -R build ~/www/html/lavender-widgets", + "deploy": "rm -rf ~/www/html/mosaic-widgets && cp -R build ~/www/html/mosaic-widgets", "clean": "rm -rf build && rm -rf dist", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { - "date-fns": "^2.30.0", + "date-fns": "^3.0.0", + "date-fns-tz": "^3.1.3", "dotenv": "^16.1.4", "lit": "^2.7.5", "typescript": "^5.1.3" diff --git a/public/affirmations.html b/public/affirmations.html index 1862cd0..5461576 100644 --- a/public/affirmations.html +++ b/public/affirmations.html @@ -5,6 +5,6 @@ - + diff --git a/public/rainfall.html b/public/rainfall.html index 2d00352..0580bff 100644 --- a/public/rainfall.html +++ b/public/rainfall.html @@ -4,6 +4,6 @@ - + diff --git a/public/rss.html b/public/rss.html index 6cba275..b38aee8 100644 --- a/public/rss.html +++ b/public/rss.html @@ -5,6 +5,6 @@ - + diff --git a/public/splork.html b/public/splork.html index 8d4fb7a..79df7a7 100644 --- a/public/splork.html +++ b/public/splork.html @@ -7,6 +7,6 @@

Splork MOTD ()

- + diff --git a/public/time.html b/public/time.html new file mode 100644 index 0000000..3e395af --- /dev/null +++ b/public/time.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/public/weather.html b/public/weather.html index c1f87e0..8275c3d 100644 --- a/public/weather.html +++ b/public/weather.html @@ -5,6 +5,6 @@ - + diff --git a/src/Affirmations.ts b/src/Affirmations.ts index 5efb5c0..80b5505 100644 --- a/src/Affirmations.ts +++ b/src/Affirmations.ts @@ -1,7 +1,7 @@ import { LitElement, css, html } from 'lit'; import { customElement } from 'lit/decorators.js'; -@customElement('lavender-affirmations') +@customElement('mosaic-affirmations') export class Affirmations extends LitElement { replaceShe = ["her", "she", "her", "herself", "she is"]; replaceThey = ["them", "they", "their", "themself", "they are"]; @@ -95,6 +95,6 @@ export class Affirmations extends LitElement { declare global { interface HTMLElementTagNameMap { - 'lavender-affirmations': Affirmations; + 'mosaic-affirmations': Affirmations; } } \ No newline at end of file diff --git a/src/RSS.ts b/src/RSS.ts index cc8ab7e..e14770c 100644 --- a/src/RSS.ts +++ b/src/RSS.ts @@ -6,7 +6,7 @@ type RSSItem = { link: string | null; } -@customElement('lavender-rss') +@customElement('mosaic-rss') export class RSS extends LitElement { rssItems: RSSItem[] = []; rssTitle = ''; @@ -116,6 +116,6 @@ export class RSS extends LitElement { declare global { interface HTMLElementTagNameMap { - 'lavender-rss': RSS; + 'mosaic-rss': RSS; } } \ No newline at end of file diff --git a/src/Rainfall.ts b/src/Rainfall.ts index cfbaa64..8f5dc0e 100644 --- a/src/Rainfall.ts +++ b/src/Rainfall.ts @@ -1,7 +1,7 @@ import { LitElement, html, css } from 'lit'; import { customElement } from 'lit/decorators.js'; -@customElement('lavender-rainfall') +@customElement('mosaic-rainfall') export class Rainfall extends LitElement { value = 0.0; @@ -13,11 +13,7 @@ export class Rainfall extends LitElement { async pullValueFromBackend() { const response = await fetch('RAINFALL_URI'); const data = await response.json(); - const result = data - .map((datum: any) => datum.value) - .reduce((accum: number, datum: number) => accum + datum, 0); - - this.setValue(result); + this.setValue(data.total_moisture); setTimeout(() => this.pullValueFromBackend(), 1000); } @@ -46,7 +42,7 @@ export class Rainfall extends LitElement { return html`
Rainfall (inches and mm water)
-
${this.value / 25.4} / ${this.value}
+
${Math.round((this.value / 25.4) * 100)/100} / ${Math.round(this.value*100)/100}
`; } @@ -54,6 +50,6 @@ export class Rainfall extends LitElement { declare global { interface HTMLElementTagNameMap { - 'lavender-rainfall': Rainfall; + 'mosaic-rainfall': Rainfall; } } \ No newline at end of file diff --git a/src/Splork.ts b/src/Splork.ts index 21dd7d5..e470cf0 100644 --- a/src/Splork.ts +++ b/src/Splork.ts @@ -1,7 +1,7 @@ import { LitElement, html, css } from 'lit'; import { customElement } from 'lit/decorators.js'; -@customElement('lavender-splork') +@customElement('mosaic-splork') export class Splork extends LitElement { value = 0.0; @@ -49,6 +49,6 @@ export class Splork extends LitElement { declare global { interface HTMLElementTagNameMap { - 'lavender-splork': Splork; + 'mosaic-splork': Splork; } } \ No newline at end of file diff --git a/src/Time.ts b/src/Time.ts new file mode 100644 index 0000000..3ca96ca --- /dev/null +++ b/src/Time.ts @@ -0,0 +1,64 @@ +import { LitElement, css, html } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import { format } from 'date-fns-tz'; + +@customElement('mosaic-time') +export class Time extends LitElement { + time = ''; + + constructor() { + super(); + this.reloadTime(); + } + + + async reloadTime() { + const date = new Date(); + const hours = date.getUTCHours(); + const minutes = date.getUTCMinutes(); + const seconds = date.getUTCSeconds(); + + let beats = (hours * 3600 + 60 * minutes + seconds) / 86.4; + + beats = Math.round(beats * 1000) / 1000; + + this.setData(`${format(date, 'yyyy-MM-dd', {timeZone: 'UTC'})}@${beats.toFixed(4)}`); + + setTimeout(() => this.reloadTime(), 10); + } + + setData(time: string) { + this.time = time; + this.requestUpdate(); + } + + static override styles = [ + css` + .gauge-body { + display: flex; + flex-direction: column; + justify-content: space-between; + align-content: space-between; + text-align: center; + } + + .gauge-label { + font-weight: bold; + } + ` + ] + override render() { + return html` +
+
Universal Decimal Time
+
⧖${this.time}
+
+`; + } +} + +declare global { + interface HTMLElementTagNameMap { + 'mosaic-time': Time; + } +} \ No newline at end of file diff --git a/src/Weather.ts b/src/Weather.ts index 3fadbb7..3c11a2f 100644 --- a/src/Weather.ts +++ b/src/Weather.ts @@ -1,7 +1,7 @@ import { LitElement, css, html } from 'lit'; import { customElement } from 'lit/decorators.js'; -@customElement('lavender-weather') +@customElement('mosaic-weather') export class Weather extends LitElement { temp = 0.0; @@ -47,7 +47,7 @@ export class Weather extends LitElement {
Temperature (in C)
${this.temp}
Temperature (in F)
-
${(this.temp*9)/5 + 32}
+
${Math.round((this.temp*9)/5 + 32)}
`; } @@ -55,6 +55,6 @@ export class Weather extends LitElement { declare global { interface HTMLElementTagNameMap { - 'lavender-weather': Weather; + 'mosaic-weather': Weather; } } \ No newline at end of file