Skip to content

An open-source, self-hosted system for apps built with web technologies.

Adopt unified appearance contracts

zohayrslileh8532ff3424db
diff --git a/bun.lock b/bun.lock
index 808602d..2a40c13 100644
--- a/bun.lock
+++ b/bun.lock
@@ -7,6 +7,7 @@
"dependencies": {
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
+ "@phreshos/core": "^0.1.41",
"@phreshos/react-ui": "^0.1.16",
"@the-link/core": "^0.3.0",
"@the-link/http": "^0.1.1",
@@ -28,7 +29,6 @@
"devDependencies": {
"@babel/core": "^7.29.7",
"@babel/plugin-proposal-decorators": "^7.29.7",
- "@phreshos/core": "^0.1.41",
"@rolldown/plugin-babel": "^0.2.3",
"@tailwindcss/vite": "^4.3.3",
"@types/adm-zip": "^0.5.8",
diff --git a/package.json b/package.json
index 18930e9..2419aad 100644
--- a/package.json
+++ b/package.json
@@ -37,6 +37,7 @@
"dependencies": {
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
+ "@phreshos/core": "^0.1.41",
"@phreshos/react-ui": "^0.1.16",
"@the-link/core": "^0.3.0",
"@the-link/http": "^0.1.1",
@@ -58,7 +59,6 @@
"devDependencies": {
"@babel/core": "^7.29.7",
"@babel/plugin-proposal-decorators": "^7.29.7",
- "@phreshos/core": "^0.1.41",
"@rolldown/plugin-babel": "^0.2.3",
"@tailwindcss/vite": "^4.3.3",
"@types/adm-zip": "^0.5.8",
diff --git a/scripts/contracts/appearance.ts b/scripts/contracts/appearance.ts
index d24e836..9142f98 100644
--- a/scripts/contracts/appearance.ts
+++ b/scripts/contracts/appearance.ts
@@ -1,6 +1,6 @@
import assert from "node:assert/strict"
import Keyv from "keyv"
-import { standardAppearance } from "@phreshos/core"
+import { defaultAppearance } from "@phreshos/core"
import AppearanceManager, { appearanceSchema } from "@server/core/appearance-manager"
import FileManager from "@libs/file-manager"
import UploadManager from "@server/core/upload-manager"
@@ -8,15 +8,15 @@ import { mkdtemp, rm } from "node:fs/promises"
import { tmpdir } from "node:os"
import { join } from "node:path"
-assert.deepEqual(appearanceSchema.parse(standardAppearance), standardAppearance)
+assert.deepEqual(appearanceSchema.parse(defaultAppearance), defaultAppearance)
assert.throws(() => appearanceSchema.parse({}))
-assert.throws(() => appearanceSchema.parse({ ...standardAppearance, accent: standardAppearance.primary }))
-assert.throws(() => appearanceSchema.parse({ ...standardAppearance, spacing: { light: 12, dark: 12 } }))
+assert.throws(() => appearanceSchema.parse({ ...defaultAppearance, accent: defaultAppearance.primary }))
+assert.throws(() => appearanceSchema.parse({ ...defaultAppearance, spacing: { light: 12, dark: 12 } }))
assert.throws(() => appearanceSchema.parse({
- ...standardAppearance,
- surface: {
- ...standardAppearance.surface,
- dark: { ...standardAppearance.surface.dark, grain: 1.01 }
+ ...defaultAppearance,
+ material: {
+ ...defaultAppearance.material,
+ dark: { ...defaultAppearance.material.dark, grain: 1.01 }
}
}))
@@ -24,11 +24,11 @@ const store = new Keyv()
const directory = await mkdtemp(join(tmpdir(), "phresh-appearance-"))
const manager = await AppearanceManager.open(store, new UploadManager(new FileManager(directory)))
-assert.deepEqual(manager.value, standardAppearance)
+assert.deepEqual(manager.value, defaultAppearance)
assert(Object.isFrozen(manager.value))
for (const role of ["background", "foreground", "primary", "secondary", "success", "warning", "danger", "info"] as const) {
- assert.deepEqual(await store.get(`appearance:${role}`), standardAppearance[role])
+ assert.deepEqual(await store.get(`appearance:${role}`), defaultAppearance[role])
const color = { light: "oklch(60% 0.2 260)", dark: "var(--custom-color)" }
await manager.update({ ...manager.value, [role]: color })
assert.deepEqual(manager.value[role], color)
@@ -60,7 +60,7 @@ for (const invalid of [{ ...shadow.light, blur: -1 }, { ...shadow.light, opacity
}
const updated = {
- ...standardAppearance,
+ ...defaultAppearance,
background: { light: "white", dark: "black" }
}
diff --git a/scripts/contracts/panel.tsx b/scripts/contracts/panel.tsx
index abc8c8b..eafb073 100644
--- a/scripts/contracts/panel.tsx
+++ b/scripts/contracts/panel.tsx
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import type { ReactNode } from "react"
import { renderToStaticMarkup } from "react-dom/server"
-import { standardAppearance } from "@phreshos/core"
+import { defaultAppearance } from "@phreshos/core"
import { AppearanceProvider } from "@phreshos/react-ui"
import CredentialsForm from "@client/view/structure/authentication/credentials-form"
import TaskbarSurface, { taskbarSurfaceClassName } from "@client/view/structure/desktop/taskbar/taskbar-surface"
@@ -10,11 +10,11 @@ import Window from "@client/view/structure/desktop/windows/window"
import StartMenuPanel from "@client/view/structure/desktop/taskbar/launcher/start-menu-panel"
function markup(children: ReactNode) {
- return renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light">{children}</AppearanceProvider>)
+ return renderToStaticMarkup(<AppearanceProvider appearance={defaultAppearance} theme="light">{children}</AppearanceProvider>)
}
function panel(html: string) {
- assert.equal(html.match(/data-surface-material=""/g)?.length, 2)
+ assert.equal(html.match(/data-material=""/g)?.length, 2)
assert.match(html, /grid-template-rows:auto minmax\(0, 1fr\)/)
assert.match(html, /margin:6px;margin-top:0/)
}
@@ -25,7 +25,7 @@ assert.match(taskbar, /<h2 id="title"/)
assert.match(taskbar, /<button>Action<\/button>/)
const window = markup(<Window icon="/icon.svg" title="Window"><iframe title="Content" /></Window>)
-assert.equal(window.match(/data-surface-material=""/g)?.length, 1)
+assert.equal(window.match(/data-material=""/g)?.length, 1)
assert.match(window, /grid-template-rows:auto minmax\(0, 1fr\)/)
assert.match(window, /data-window-content="true"/)
assert.doesNotMatch(window, /border-top:1px solid yellow/)
@@ -33,10 +33,9 @@ assert.doesNotMatch(window, /margin:6px;margin-top:0/)
assert.match(window, /data-window-container/)
assert.match(window, /<iframe title="Content"/)
assert.doesNotMatch(window, /class="p-px"/)
-assert.match(window, /data-surface-border=""[^>]*z-index:1/)
const bare = markup(<Window bare icon="/icon.svg" title="Bare"><iframe title="Content" /></Window>)
-assert.doesNotMatch(bare, /data-surface-material/)
+assert.doesNotMatch(bare, /data-material/)
assert.doesNotMatch(bare, /grid-template-rows:auto minmax\(0, 1fr\)/)
const authentication = markup(<CredentialsForm title="Sign in" description="Welcome" submitLabel="Continue" passwordAutocomplete="current-password" pending={false} onSubmit={() => {}} />)
@@ -47,7 +46,7 @@ assert.match(authentication, /name="password"/)
assert.match(authentication, /type="submit"/)
const launcher = markup(<Launcher label="Example System" trigger="Open">{(_close, labelId) => <StartMenuPanel labelId={labelId} name="Example System" version="1.2.3" left={<button>Programs</button>} right={<p>Processes</p>} footer={<input type="search" aria-label="Search Programs and Processes" />} />}</Launcher>)
-assert.equal(launcher.match(/data-surface-material=""/g)?.length, 4)
+assert.equal(launcher.match(/data-material=""/g)?.length, 4)
assert.match(launcher, /grid-cols-2/)
assert.match(launcher, /grid-template-rows:auto minmax\(0, 1fr\);min-height:0/)
assert.match(launcher, /grid-template-rows:minmax\(0, 1fr\) auto;gap:8px;padding:8px;padding-top:0/)
diff --git a/scripts/contracts/start-menu-search.tsx b/scripts/contracts/start-menu-search.tsx
index a64acaf..fd8a815 100644
--- a/scripts/contracts/start-menu-search.tsx
+++ b/scripts/contracts/start-menu-search.tsx
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import { renderToStaticMarkup } from "react-dom/server"
import { AppearanceProvider } from "@phreshos/react-ui"
-import { standardAppearance } from "@phreshos/core"
+import { defaultAppearance } from "@phreshos/core"
import Program from "@server/core/link-manager/auth-manager/program-manager/program"
import SearchBar from "@client/view/structure/desktop/taskbar/launcher/search-bar"
import { matchesProcess, matchesProgram, searchTerms } from "@client/view/structure/desktop/taskbar/launcher/search"
@@ -36,12 +36,12 @@ assert(matchesProcess(null, undefined, searchTerms("")))
assert(!matchesProcess(null, undefined, searchTerms("notes")))
assert(!matchesProcess("daily draft", program, searchTerms("missing")))
-const footer = renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light"><SearchBar query="notes" onChange={() => {}} /></AppearanceProvider>)
+const footer = renderToStaticMarkup(<AppearanceProvider appearance={defaultAppearance} theme="light"><SearchBar query="notes" onChange={() => {}} /></AppearanceProvider>)
assert.match(footer, /<div class="react-aria-TextField"/)
assert.match(footer, /<input\b/)
assert.match(footer, /value="notes"/)
assert.match(footer, /aria-label="Search Programs and Processes"/)
-assert.equal(footer.match(/data-surface-material=""/g)?.length, 1)
+assert.equal(footer.match(/data-material=""/g)?.length, 1)
assert.doesNotMatch(footer, /<(?:main|section|article|aside|nav|header|footer)\b/)
assert.doesNotMatch(footer, /Signed in as/)
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index 7b829f9..ae3faac 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -1,5 +1,5 @@
import DesktopPreferencesProvider, { useDesktopPreferences } from "./desktop-preferences"
-import { standardAppearance } from "@phreshos/core"
+import { defaultAppearance } from "@phreshos/core"
import ReducedMotion from "@libs/react-motion"
import { PropsWithChildren } from "react"
import "./appearance.css"
@@ -15,7 +15,7 @@ export default function ({ children }: PropsWithChildren) {
function AppearanceRoot({ children }: PropsWithChildren) {
const { preferences } = useDesktopPreferences()
- const background = standardAppearance.background[preferences.theme]
+ const background = defaultAppearance.background[preferences.theme]
return <ReducedMotion reduced={!preferences.animations}>
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index b685608..46f4372 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -11,7 +11,7 @@ import { useDesktopPreferences } from "../appearance/desktop-preferences"
import Authentication from "./authentication/authentication"
import { useCallback, useEffect, useState } from "react"
import Readiness, { useReady } from "@libs/readiness"
-import { standardAppearance, type DesktopPreferencesUpdate } from "@phreshos/core"
+import { defaultAppearance, type DesktopPreferencesUpdate } from "@phreshos/core"
const startupRequirements = ["connection", "session", "wallpaper"] as const
@@ -31,7 +31,7 @@ export default function () {
? "opacity-100"
: "pointer-events-none opacity-0 transition-opacity duration-200 ease-out"}
- style={{ backgroundColor: standardAppearance.background.light }}
+ style={{ backgroundColor: defaultAppearance.background.light }}
/>}
diff --git a/source/server/core/appearance-manager.ts b/source/server/core/appearance-manager.ts
index 2b6aa24..fdef152 100644
--- a/source/server/core/appearance-manager.ts
+++ b/source/server/core/appearance-manager.ts
@@ -4,7 +4,7 @@ import { z } from "zod"
import {
appearanceLimits,
createAppearanceSnapshot,
- standardAppearance,
+ defaultAppearance,
type Appearance,
type AppearanceRange
} from "@phreshos/core"
@@ -14,13 +14,13 @@ const servedFileSchema = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-
const wallpaperSchema = servedFileSchema.nullable()
const wallpaperExtensions = new Set(["avif", "bmp", "gif", "jpeg", "jpg", "png", "svg", "webp"])
-const surfaceSchema = z.strictObject({
- grain: bounded(appearanceLimits.surface.grain),
- grainAmount: bounded(appearanceLimits.surface.grainAmount),
- backdrop: bounded(appearanceLimits.surface.backdrop),
- opacity: bounded(appearanceLimits.surface.opacity),
- distortion: bounded(appearanceLimits.surface.distortion),
- saturation: bounded(appearanceLimits.surface.saturation)
+const materialSchema = z.strictObject({
+ grain: bounded(appearanceLimits.material.grain),
+ grainAmount: bounded(appearanceLimits.material.grainAmount),
+ backdrop: bounded(appearanceLimits.material.backdrop),
+ opacity: bounded(appearanceLimits.material.opacity),
+ distortion: bounded(appearanceLimits.material.distortion),
+ saturation: bounded(appearanceLimits.material.saturation)
})
const shadowSchema = z.strictObject({
@@ -44,12 +44,12 @@ export const appearanceSchema: z.ZodType<Appearance> = z.strictObject({
spacing: shared(bounded(appearanceLimits.spacing)),
radius: shared(bounded(appearanceLimits.radius)),
shadow: themed(shadowSchema),
- surface: themed(surfaceSchema),
+ material: themed(materialSchema),
signInWallpaper: themed(wallpaperSchema),
desktopWallpaper: themed(wallpaperSchema)
})
-const properties = Object.keys(standardAppearance) as (keyof Appearance)[]
+const properties = Object.keys(defaultAppearance) as (keyof Appearance)[]
/** Durable, complete Appearance state owned by Server Core. */
export default class AppearanceManager {
@@ -66,7 +66,7 @@ export default class AppearanceManager {
})))
const stored = Object.fromEntries(entries.map(({ property, value }) => [
property,
- value === undefined ? standardAppearance[property] : value
+ value === undefined ? defaultAppearance[property] : value
]))
const appearance = createAppearanceSnapshot(appearanceSchema.parse(stored))